wobblyhead hg > 3dprints > hinged_box
comparison main.scad @ 10:a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
Add back_side to put the hinge or a latch on the back, and latch_front,
latch_left and latch_right checkboxes. The latch hardware is modelled in
a face frame and placed on each latched side. All latches share one
width, clamped to the narrowest latched face; the console lists the
latched sides and the number of latches to print. A layout other than
front latch with back hinge adds an l token with the side letters to
the file name.
Replace preview_lid_angle with preview_lid_open in percent: with the
hinge 100 turns the lid by 180 degrees, without it lifts the lid by one
body height. Presets converted. README updated.
| author | ark |
|---|---|
| date | 2026-11-17 12:53 +0100 |
| parents | 4b89f95689a8 |
| children | 7bef1d0cb914 |
comparison
equal
deleted
inserted
replaced
| 9:4b89f95689a8 | 10:a7a1b12fd6bf |
|---|---|
| 1 // hinged box with filament hinge at the back and a hinged latch in front. | 1 // hinged box with a filament hinge or a latch at the back and hinged |
| 2 // sized by its inner dimensions, e.g. for standing notepad paper. | 2 // latches on any of the other sides. sized by its inner dimensions, e.g. |
| 3 // x runs front (-x) to back (+x), y left to right, z up. | 3 // for standing notepad paper. |
| 4 // x runs front (-x) to back (+x), y right (-y) to left (+y) seen from the | |
| 5 // front, z up. | |
| 4 // the preview turns the model 90 degrees so the front faces -y. | 6 // the preview turns the model 90 degrees so the front faces -y. |
| 5 | 7 |
| 6 /* [part selection] */ | 8 /* [part selection] */ |
| 7 // part to show or export | 9 // part to show or export |
| 8 part = "all"; // [all, body, lid, latch] | 10 part = "all"; // [all, body, lid, latch] |
| 10 preview_cut = false; | 12 preview_cut = false; |
| 11 // show a content mockup in each cell in the assembly view | 13 // show a content mockup in each cell in the assembly view |
| 12 preview_content = false; | 14 preview_content = false; |
| 13 // show the filament pins and latch bar in the assembly view | 15 // show the filament pins and latch bar in the assembly view |
| 14 preview_hardware = false; | 16 preview_hardware = false; |
| 15 // lid opening angle in the assembly view | 17 // lid opening in percent in the assembly view |
| 16 preview_lid_angle = 0; // [0:1:180] | 18 preview_lid_open = 0; // [0:1:100] |
| 17 // latch opening angle in the assembly view | 19 // opening angle of all latches in the assembly view |
| 18 preview_latch_angle = 0; // [0:1:75] | 20 preview_latch_angle = 0; // [0:1:75] |
| 19 | 21 |
| 20 /* [box] */ | 22 /* [box] */ |
| 21 // inner size front to back, of one cell | 23 // inner size front to back, of one cell |
| 22 inner_depth = 92; // [10:.1:300] | 24 inner_depth = 92; // [10:.1:300] |
| 64 hinge_knuckles = 5; // [3:2:15] | 66 hinge_knuckles = 5; // [3:2:15] |
| 65 // knuckle wall around the pin hole, in extrusions | 67 // knuckle wall around the pin hole, in extrusions |
| 66 hinge_lines = 3; // [2:1:8] | 68 hinge_lines = 3; // [2:1:8] |
| 67 | 69 |
| 68 /* [latch] */ | 70 /* [latch] */ |
| 71 // back of the box: the hinge, or a latch for a removable lid | |
| 72 back_side = "hinge"; // [hinge, latch] | |
| 73 // latch on the front | |
| 74 latch_front = true; | |
| 75 // latch on the left side, seen from the front | |
| 76 latch_left = false; | |
| 77 // latch on the right side, seen from the front | |
| 78 latch_right = false; | |
| 69 // latch shape: a plate in front of the knuckles joining knuckle and hook, or a solid block between the bar knuckles | 79 // latch shape: a plate in front of the knuckles joining knuckle and hook, or a solid block between the bar knuckles |
| 70 latch_style = "plate"; // [plate, block] | 80 latch_style = "plate"; // [plate, block] |
| 71 // latch width | 81 // latch width, the same for all latches |
| 72 latch_width = 20; // [8:1:100] | 82 latch_width = 20; // [8:1:100] |
| 73 // share of the latch width taken by the middle knuckle that carries the latch. the outer knuckles share the rest | 83 // share of the latch width taken by the middle knuckle that carries the latch. the outer knuckles share the rest |
| 74 latch_middle_ratio = .33; // [.1:.01:.9] | 84 latch_middle_ratio = .33; // [.1:.01:.9] |
| 75 // plate style: plate across the full latch width, printed flat. otherwise only as wide as the middle knuckle, printed standing on its side | 85 // plate style: plate across the full latch width, printed flat. otherwise only as wide as the middle knuckle, printed standing on its side |
| 76 latch_plate_full = true; | 86 latch_plate_full = true; |
| 132 seam_z = floor_t + body_ih; | 142 seam_z = floor_t + body_ih; |
| 133 top_z = floor_t + inner_height + floor_t; | 143 top_z = floor_t + inner_height + floor_t; |
| 134 lid_h = top_z - seam_z; | 144 lid_h = top_z - seam_z; |
| 135 | 145 |
| 136 // hinge | 146 // hinge |
| 147 back_hinge = back_side == "hinge"; | |
| 137 hinge_x = out_x/2 + knuckle_u; | 148 hinge_x = out_x/2 + knuckle_u; |
| 138 hinge_span = out_y - 2*edge_r; | 149 hinge_span = out_y - 2*edge_r; |
| 139 knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles; | 150 knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles; |
| 140 | 151 |
| 152 // sides that can take a latch: front, back, left, right. side_a turns the | |
| 153 // front to that side, side_d is the distance of its face from the centre, | |
| 154 // side_span the length of the face between the edge roundings | |
| 155 side_name = ["front", "back", "left", "right"]; | |
| 156 side_a = [0, 180, -90, 90]; | |
| 157 side_d = [out_x/2, out_x/2, out_y/2, out_y/2]; | |
| 158 side_span = [out_y - 2*edge_r, out_y - 2*edge_r, out_x - 2*edge_r, out_x - 2*edge_r]; | |
| 159 side_on = [latch_front, !back_hinge, latch_left, latch_right]; | |
| 160 latch_sides = [for (i = [0:3]) if (side_on[i]) i]; | |
| 161 | |
| 141 // latch. the latch hangs from lid knuckles and its hook wraps around a | 162 // latch. the latch hangs from lid knuckles and its hook wraps around a |
| 142 // filament bar held by body knuckles straight below the latch axis. | 163 // filament bar held by body knuckles straight below the latch axis. the |
| 143 // in the front frame u runs outward from the front face, z up. | 164 // latch hardware is modelled in a face frame: u runs outward from the |
| 144 // a latch wider than the hinge span is narrowed to it | 165 // face, y along it, z up. all latches have the same width; one wider than |
| 145 latch_w = min(latch_width, hinge_span); | 166 // the narrowest latched face is narrowed to it |
| 146 latch_x = -out_x/2 - knuckle_u; | 167 latch_w = min(concat([latch_width], [for (i = latch_sides) side_span[i]])); |
| 147 latch_z = seam_z + knuckle_r + cl; | 168 latch_z = seam_z + knuckle_r + cl; |
| 148 bar_z = seam_z - cl - knuckle_r; | 169 bar_z = seam_z - cl - knuckle_r; |
| 149 bar_r = filament_diameter/2; | 170 bar_r = filament_diameter/2; |
| 150 // distance between flap axis and bar axis | 171 // distance between flap axis and bar axis |
| 151 bar_h = latch_z - bar_z; | 172 bar_h = latch_z - bar_z; |
| 160 n == 0 ? (lo + hi)/2 : | 181 n == 0 ? (lo + hi)/2 : |
| 161 let(m = (lo + hi)/2) | 182 let(m = (lo + hi)/2) |
| 162 _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1); | 183 _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1); |
| 163 hook_a = _hook_angle(0, 90); | 184 hook_a = _hook_angle(0, 90); |
| 164 | 185 |
| 186 // strings in v joined with sep between them | |
| 187 function _join(v, sep="", i=0) = | |
| 188 i >= len(v) ? "" : str(i > 0 ? sep : "", v[i], _join(v, sep, i + 1)); | |
| 189 | |
| 165 // knuckle slots across the latch width: the middle one carries the latch, | 190 // knuckle slots across the latch width: the middle one carries the latch, |
| 166 // the outer ones have a lid knuckle above and a body knuckle below. a | 191 // the outer ones have a lid knuckle above and a body knuckle below. a |
| 167 // ratio that leaves a slot narrower than 2 extrusions is clamped | 192 // ratio that leaves a slot narrower than 2 extrusions is clamped |
| 168 latch_span = latch_w - 2*knuckle_gap; | 193 latch_span = latch_w - 2*knuckle_gap; |
| 169 slot_min = 2*lw; | 194 slot_min = 2*lw; |
| 197 // fingernail notch in the back face at the bottom edge: 3 extrusions | 222 // fingernail notch in the back face at the bottom edge: 3 extrusions |
| 198 // deep, 8 extrusions high, kept 2 extrusions below the hook | 223 // deep, 8 extrusions high, kept 2 extrusions below the hook |
| 199 nail_d = 3*lw; | 224 nail_d = 3*lw; |
| 200 nail_h = min(8*lw, bar_z - hook_ro - 2*lw - blk_bz); | 225 nail_h = min(8*lw, bar_z - hook_ro - 2*lw - blk_bz); |
| 201 | 226 |
| 202 // how far the latch reaches out from the front face | 227 // how far the latch reaches out from the face |
| 203 latch_front_u = latch_block ? knuckle_u + blk_r : plate_u + plate_t; | 228 latch_front_u = latch_block ? knuckle_u + blk_r : plate_u + plate_t; |
| 204 | 229 |
| 205 assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar"); | 230 assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar"); |
| 206 assert(knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); | 231 assert(!back_hinge || knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); |
| 207 assert(body_ih > 0, "inner height too low for the lid"); | 232 assert(body_ih > 0, "inner height too low for the lid"); |
| 208 assert(chamfer_h <= floor_t, "chamfer higher than the floor"); | 233 assert(chamfer_h <= floor_t, "chamfer higher than the floor"); |
| 209 | 234 |
| 210 // cell centres: x for row i from the front, y for column j from the left | 235 // cell centres: x for row i from the front, y for column j from the left |
| 211 function _cell_x(i) = -in_x/2 + inner_depth/2 + i*(inner_depth + div_t); | 236 function _cell_x(i) = -in_x/2 + inner_depth/2 + i*(inner_depth + div_t); |
| 232 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers"); | 257 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers"); |
| 233 if (body_ih < body_ih_req) | 258 if (body_ih < body_ih_req) |
| 234 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ", | 259 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ", |
| 235 body_ih/inner_height)); | 260 body_ih/inner_height)); |
| 236 echo("body height", seam_z, "mm, lid height", lid_h, "mm, body ratio", body_ih/inner_height); | 261 echo("body height", seam_z, "mm, lid height", lid_h, "mm, body ratio", body_ih/inner_height); |
| 262 echo(str("back: ", back_side, ", latches: ", | |
| 263 len(latch_sides) == 0 ? "none" : _join([for (i = latch_sides) side_name[i]], ", "), | |
| 264 ", print ", len(latch_sides), len(latch_sides) == 1 ? " latch" : " latches")); | |
| 237 if (latch_w < latch_width) | 265 if (latch_w < latch_width) |
| 238 echo(str("WARNING: latch_width ", latch_width, " is wider than the hinge span, using ", | 266 echo(str("WARNING: latch_width ", latch_width, " is wider than the narrowest latched face, using ", |
| 239 latch_w)); | 267 latch_w)); |
| 240 if (latch_ratio != latch_middle_ratio) | 268 if (latch_ratio != latch_middle_ratio) |
| 241 echo(str("WARNING: latch_middle_ratio ", latch_middle_ratio, | 269 echo(str("WARNING: latch_middle_ratio ", latch_middle_ratio, |
| 242 " leaves a latch knuckle narrower than 2 extrusions, using ", latch_ratio)); | 270 " leaves a latch knuckle narrower than 2 extrusions, using ", latch_ratio)); |
| 243 echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm"); | 271 echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm"); |
| 244 echo("hinge knuckle length", knuckle_l, "mm"); | 272 if (back_hinge) |
| 273 echo("hinge knuckle length", knuckle_l, "mm"); | |
| 245 echo("latch knuckle length: middle", latch_mid, "mm, outer", latch_outer, "mm"); | 274 echo("latch knuckle length: middle", latch_mid, "mm, outer", latch_outer, "mm"); |
| 246 echo(str("latch style ", latch_style, ", printed ", latch_on_side ? "on its side" : "flat")); | 275 echo(str("latch style ", latch_style, ", printed ", latch_on_side ? "on its side" : "flat")); |
| 247 if (latch_block) { | 276 if (latch_block) { |
| 248 echo("latch block length below the hook", latch_grip, "mm"); | 277 echo("latch block length below the hook", latch_grip, "mm"); |
| 249 if (nail_h > 0) | 278 if (nail_h > 0) |
| 252 echo("WARNING: latch_grip too short for the fingernail notch"); | 281 echo("WARNING: latch_grip too short for the fingernail notch"); |
| 253 } else if (latch_on_side) | 282 } else if (latch_on_side) |
| 254 echo("latch plate thickness", plate_t, "mm", plate_lines, "extrusions, width", plate_w, "mm"); | 283 echo("latch plate thickness", plate_t, "mm", plate_lines, "extrusions, width", plate_w, "mm"); |
| 255 else | 284 else |
| 256 echo("latch plate thickness", plate_t, "mm", latch_layers, "layers, width", plate_w, "mm"); | 285 echo("latch plate thickness", plate_t, "mm", latch_layers, "layers, width", plate_w, "mm"); |
| 257 echo("latch outer face", latch_front_u, "mm from the front"); | 286 echo("latch outer face", latch_front_u, "mm from the box face"); |
| 258 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm"); | 287 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm"); |
| 259 if (cont_x < content_depth) | 288 if (cont_x < content_depth) |
| 260 echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x)); | 289 echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x)); |
| 261 if (cont_y < content_width) | 290 if (cont_y < content_width) |
| 262 echo(str("WARNING: content_width ", content_width, " is larger than the cell, using ", cont_y)); | 291 echo(str("WARNING: content_width ", content_width, " is larger than the cell, using ", cont_y)); |
| 263 if (cont_z < content_height) | 292 if (cont_z < content_height) |
| 264 echo(str("WARNING: content_height ", content_height, " is larger than the inner height, using ", | 293 echo(str("WARNING: content_height ", content_height, " is larger than the inner height, using ", |
| 265 cont_z)); | 294 cont_z)); |
| 266 echo("lid sweep clearance over the content in the front row", sweep_margin, "mm"); | 295 if (back_hinge) |
| 296 echo("lid sweep clearance over the content in the front row", sweep_margin, "mm"); | |
| 267 | 297 |
| 268 // rounded box outline, inset by d | 298 // rounded box outline, inset by d |
| 269 module _outline(d) { | 299 module _outline(d) { |
| 270 r = max(edge_r - d, 0); | 300 r = max(edge_r - d, 0); |
| 271 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true); | 301 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true); |
| 287 // frame with u outward from the back face | 317 // frame with u outward from the back face |
| 288 module _back() { | 318 module _back() { |
| 289 translate([out_x/2, 0, 0]) children(); | 319 translate([out_x/2, 0, 0]) children(); |
| 290 } | 320 } |
| 291 | 321 |
| 292 // frame with u outward from the front face | 322 // face frame of side i: u outward from the face, y along it |
| 293 module _front() { | 323 module _side(i) { |
| 294 translate([-out_x/2, 0, 0]) mirror([1, 0, 0]) children(); | 324 rotate([0, 0, side_a[i]]) translate([-side_d[i], 0, 0]) mirror([1, 0, 0]) children(); |
| 295 } | 325 } |
| 296 | 326 |
| 297 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap); | 327 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap); |
| 298 | 328 |
| 299 module _hinge_pin() { | 329 module _hinge_pin() { |
| 300 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0]) | 330 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0]) |
| 301 cylinder(d=pin_d, h=out_y + 2, center=true); | 331 cylinder(d=pin_d, h=out_y + 2, center=true); |
| 302 } | 332 } |
| 303 | 333 |
| 334 // latch pin hole in the face frame | |
| 304 module _latch_pin() { | 335 module _latch_pin() { |
| 305 translate([latch_x, 0, latch_z]) rotate([90, 0, 0]) | 336 translate([knuckle_u, 0, latch_z]) rotate([90, 0, 0]) |
| 306 cylinder(d=pin_d, h=latch_w + 2, center=true); | 337 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 307 } | 338 } |
| 308 | 339 |
| 340 // bar hole in the face frame | |
| 309 module _bar_pin() { | 341 module _bar_pin() { |
| 310 translate([latch_x, 0, bar_z]) rotate([90, 0, 0]) | 342 translate([knuckle_u, 0, bar_z]) rotate([90, 0, 0]) |
| 311 cylinder(d=pin_d, h=latch_w + 2, center=true); | 343 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 312 } | 344 } |
| 313 | 345 |
| 314 module body() { | 346 module body() { |
| 315 // divider walls between the cells, reaching into the outer wall | 347 // divider walls between the cells, reaching into the outer wall |
| 339 linear_extrude(lip_h + epsilon) | 371 linear_extrude(lip_h + epsilon) |
| 340 difference() { | 372 difference() { |
| 341 _outline(skirt_t + cl); | 373 _outline(skirt_t + cl); |
| 342 _outline(wall_t); | 374 _outline(wall_t); |
| 343 } | 375 } |
| 344 for (i = [0:2:hinge_knuckles - 1]) | 376 if (back_hinge) |
| 345 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) | 377 for (i = [0:2:hinge_knuckles - 1]) |
| 346 _knuckle(seam_z, seam_z - cl); | 378 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) |
| 347 for (y0 = latch_outer_y0) | 379 _knuckle(seam_z, seam_z - cl); |
| 348 _front() _yslab(y0, y0 + latch_outer) _knuckle(bar_z, bar_z + knuckle_r); | 380 for (i = latch_sides, y0 = latch_outer_y0) |
| 381 _side(i) _yslab(y0, y0 + latch_outer) _knuckle(bar_z, bar_z + knuckle_r); | |
| 349 } | 382 } |
| 350 translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t); | 383 translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t); |
| 351 _hinge_pin(); | 384 if (back_hinge) _hinge_pin(); |
| 352 _bar_pin(); | 385 for (i = latch_sides) _side(i) _bar_pin(); |
| 353 } | 386 } |
| 354 // dividers from the floor to the top of the lip | 387 // dividers from the floor to the top of the lip |
| 355 translate([0, 0, floor_t - epsilon]) | 388 translate([0, 0, floor_t - epsilon]) |
| 356 linear_extrude(seam_z + lip_h - floor_t + epsilon) _dividers(); | 389 linear_extrude(seam_z + lip_h - floor_t + epsilon) _dividers(); |
| 357 } | 390 } |
| 384 } | 417 } |
| 385 | 418 |
| 386 difference() { | 419 difference() { |
| 387 union() { | 420 union() { |
| 388 translate([0, 0, top_z]) mirror([0, 0, 1]) _block(lid_h); | 421 translate([0, 0, top_z]) mirror([0, 0, 1]) _block(lid_h); |
| 389 for (i = [1:2:hinge_knuckles - 1]) | 422 if (back_hinge) |
| 390 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) | 423 for (i = [1:2:hinge_knuckles - 1]) |
| 391 _knuckle(seam_z, seam_z + cl); | 424 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) |
| 392 for (y0 = latch_outer_y0) | 425 _knuckle(seam_z, seam_z + cl); |
| 393 _front() _yslab(y0, y0 + latch_outer) _knuckle(latch_z, seam_z + cl); | 426 for (i = latch_sides, y0 = latch_outer_y0) |
| 427 _side(i) _yslab(y0, y0 + latch_outer) _knuckle(latch_z, seam_z + cl); | |
| 394 } | 428 } |
| 395 translate([0, 0, seam_z - epsilon]) | 429 translate([0, 0, seam_z - epsilon]) |
| 396 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t); | 430 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t); |
| 397 // recess over the lip, one layer higher than the lip | 431 // recess over the lip, one layer higher than the lip |
| 398 translate([0, 0, seam_z - epsilon]) | 432 translate([0, 0, seam_z - epsilon]) |
| 399 linear_extrude(lip_h + lh + epsilon) _outline(skirt_t); | 433 linear_extrude(lip_h + lh + epsilon) _outline(skirt_t); |
| 400 _hinge_pin(); | 434 if (back_hinge) _hinge_pin(); |
| 401 _latch_pin(); | 435 for (i = latch_sides) _side(i) _latch_pin(); |
| 402 } | 436 } |
| 403 } | 437 } |
| 404 | 438 |
| 405 // in assembly position, closed. the plate style has a knuckle and a hook | 439 // in the face frame, closed. the plate style has a knuckle and a hook |
| 406 // in the middle slot, joined by a plate in front of the outer knuckles. the | 440 // in the middle slot, joined by a plate in front of the outer knuckles. the |
| 407 // block style is one solid profile across the middle slot | 441 // block style is one solid profile across the middle slot |
| 408 module latch() { | 442 module latch() { |
| 409 tip_a = 270 - hook_a; | 443 tip_a = 270 - hook_a; |
| 410 axis = [knuckle_u, latch_z]; | 444 axis = [knuckle_u, latch_z]; |
| 483 square([nail_d + epsilon, nail_h + epsilon]); | 517 square([nail_d + epsilon, nail_h + epsilon]); |
| 484 } | 518 } |
| 485 } | 519 } |
| 486 | 520 |
| 487 difference() { | 521 difference() { |
| 488 _front() | 522 if (latch_block) _yslab(-latch_mid/2, latch_mid/2) _block(); |
| 489 if (latch_block) _yslab(-latch_mid/2, latch_mid/2) _block(); | 523 else _plate(); |
| 490 else _plate(); | |
| 491 _latch_pin(); | 524 _latch_pin(); |
| 492 } | 525 } |
| 493 } | 526 } |
| 494 | 527 |
| 495 // content block centred in each cell | 528 // content block centred in each cell |
| 504 module _filament(x, z, l) { | 537 module _filament(x, z, l) { |
| 505 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0]) | 538 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0]) |
| 506 cylinder(d=filament_diameter, h=l, center=true); | 539 cylinder(d=filament_diameter, h=l, center=true); |
| 507 } | 540 } |
| 508 | 541 |
| 542 // the lid turns about the hinge axis with the back hinge, otherwise it | |
| 543 // lifts straight up. in the face frame, a latch opens with its bottom | |
| 544 // swinging outward | |
| 509 module _assembly() { | 545 module _assembly() { |
| 546 lid_a = back_hinge ? 1.8*preview_lid_open : 0; | |
| 547 lid_lift = back_hinge ? 0 : preview_lid_open/100*seam_z; | |
| 510 color("steelblue") body(); | 548 color("steelblue") body(); |
| 511 if (preview_hardware && $preview) { | 549 if (preview_hardware && $preview) { |
| 512 _filament(hinge_x, seam_z, hinge_span); | 550 if (back_hinge) _filament(hinge_x, seam_z, hinge_span); |
| 513 _filament(latch_x, bar_z, latch_w); | 551 for (i = latch_sides) _side(i) _filament(knuckle_u, bar_z, latch_w); |
| 514 } | 552 } |
| 515 translate([hinge_x, 0, seam_z]) rotate([0, preview_lid_angle, 0]) | 553 translate([hinge_x, 0, seam_z + lid_lift]) rotate([0, lid_a, 0]) |
| 516 translate([-hinge_x, 0, -seam_z]) { | 554 translate([-hinge_x, 0, -seam_z]) { |
| 517 color("lightsteelblue") lid(); | 555 color("lightsteelblue") lid(); |
| 518 if (preview_hardware && $preview) _filament(latch_x, latch_z, latch_w); | 556 for (i = latch_sides) _side(i) { |
| 519 translate([latch_x, 0, latch_z]) rotate([0, preview_latch_angle, 0]) | 557 if (preview_hardware && $preview) _filament(knuckle_u, latch_z, latch_w); |
| 520 translate([-latch_x, 0, -latch_z]) color("orange") latch(); | 558 translate([knuckle_u, 0, latch_z]) rotate([0, -preview_latch_angle, 0]) |
| 559 translate([-knuckle_u, 0, -latch_z]) color("orange") latch(); | |
| 560 } | |
| 521 } | 561 } |
| 522 if (preview_content && $preview) _content(); | 562 if (preview_content && $preview) _content(); |
| 523 } | 563 } |
| 524 | 564 |
| 525 // in preview, turn the model so its front faces the default camera at -y, | 565 // in preview, turn the model so its front faces the default camera at -y, |
| 526 // and with preview_cut remove the +x half, the right half seen from the | 566 // and with preview_cut remove the +x half, the right half seen from the |
| 527 // front. exports stay unturned | 567 // front. exports stay unturned |
| 528 module part_view() { | 568 module part_view() { |
| 529 cut_s = max(out_x/2 + latch_front_u, top_z) | 569 cut_s = max(max(out_x, out_y)/2 + latch_front_u, hinge_x + knuckle_r, top_z) |
| 530 + (preview_lid_angle > 0 ? out_x : 0) + 1; | 570 + (preview_lid_open > 0 ? (back_hinge ? out_x : seam_z) : 0) + 1; |
| 531 if ($preview) | 571 if ($preview) |
| 532 difference() { | 572 difference() { |
| 533 rotate([0, 0, 90]) children(); | 573 rotate([0, 0, 90]) children(); |
| 534 if (preview_cut) translate([0, -cut_s, -cut_s]) cube([cut_s, 2*cut_s, 2*cut_s]); | 574 if (preview_cut) translate([0, -cut_s, -cut_s]) cube([cut_s, 2*cut_s, 2*cut_s]); |
| 535 } | 575 } |
| 550 part_view() | 590 part_view() |
| 551 if ($preview) latch(); | 591 if ($preview) latch(); |
| 552 // on its side: the width along z, standing on the print bed | 592 // on its side: the width along z, standing on the print bed |
| 553 else if (latch_on_side) | 593 else if (latch_on_side) |
| 554 translate([0, 0, latch_mid/2]) rotate([90, 0, 0]) | 594 translate([0, 0, latch_mid/2]) rotate([90, 0, 0]) |
| 555 translate([-latch_x, 0, -latch_z]) latch(); | 595 translate([-knuckle_u, 0, -latch_z]) latch(); |
| 556 // flat: the plate face on the print bed | 596 // flat: the plate face on the print bed |
| 557 else translate([latch_z, 0, out_x/2 + latch_front_u]) | 597 else translate([-latch_z, 0, latch_front_u]) |
| 558 rotate([0, -90, 0]) latch(); | 598 rotate([0, 90, 0]) latch(); |
| 559 } | 599 } |
| 560 | 600 |
| 561 main(); | 601 main(); |
| 562 | 602 |
| 563 function paramstring(prefix="", suffix="") = str( | 603 function paramstring(prefix="", suffix="") = str( |
| 564 prefix, | 604 prefix, |
| 565 part == "all" ? "" : str(part, "_"), | 605 part == "all" ? "" : str(part, "_"), |
| 566 part == "latch" ? | 606 part == "latch" ? |
| 567 str(latch_block ? "block" : latch_plate_full ? "plate" : "plate-middle", "_") : "", | 607 str(latch_block ? "block" : latch_plate_full ? "plate" : "plate-middle", "_") : "", |
| 568 columns > 1 || rows > 1 ? str("c", columns, "r", rows, "_") : "", | 608 columns > 1 || rows > 1 ? str("c", columns, "r", rows, "_") : "", |
| 609 // latched sides, only when they differ from the front latch and back hinge | |
| 610 side_on == [true, false, false, false] ? "" : | |
| 611 str("l", _join([for (i = latch_sides) "fblr"[i]]), "_"), | |
| 569 "w", inner_width, "d", inner_depth, "h", inner_height, | 612 "w", inner_width, "d", inner_depth, "h", inner_height, |
| 570 "b", round(100*body_ih/inner_height), | 613 "b", round(100*body_ih/inner_height), |
| 571 // latch middle share, only when it differs from the default | 614 // latch middle share, only when it differs from the default |
| 572 round(100*latch_ratio) == 33 ? "" : str("lm", round(100*latch_ratio)), | 615 round(100*latch_ratio) == 33 ? "" : str("lm", round(100*latch_ratio)), |
| 573 "_lw", round(100*line_width), "lh", round(100*layer_height), | 616 "_lw", round(100*line_width), "lh", round(100*layer_height), |
