Ammo Can

Nov 14, 2026 12:24am · 53 views
openscad
Code 23,194 characters
// ============================================================================
// UNIVERSAL AUTO-SIZING POCKET AMMO CARRIER (100% SUPPORT-FREE EDITION)
// Modes: "round" (Captive Rotating Turret) | "square" (Hinged Clamshell + Latch)
// ============================================================================
$fn = 90;

/* [1. Primary Configuration] */
box_shape     = "square";     // ["round", "square"]
filament_type = "PETG";       // ["PETG", "PLA"]
caliber       = "22LR";       // ["22LR", "22WMR", "17HMR", "9MM", "380ACP", "38SPL", "357MAG", "45ACP", "223REM", "Custom"]
round_count   = 50;           // Type any exact round count
render_part   = "both";       // ["base", "lid", "both"]

/* [2. Custom Text / Logo Settings] */
show_text        = true;
primary_text     = "SOUTH SIDE COON CLUB";
secondary_text   = "AUTO";    // "AUTO" prints "[CALIBER] โ€ข [COUNT] RDS", or enter custom text
text_font        = "Liberation Sans:style=Bold";
font_bold_offset = 0.22;      // Thickens font strokes (mm) so letters print bold & crisp
engrave_depth    = 0.55;      // Recessed depth on top face (prints face-down cleanly)

/* [3. Structural Safeguards] */
min_web_wall     = 1.45;      // Minimum solid wall between chambers (mm)
outer_wall_thick = 2.60;      // Perimeter wall thickness (mm)
floor_thick      = 2.20;      // Solid bottom thickness (mm)
expose_tip_mm    = 5.20;      // Exposed cartridge height for easy finger grab (mm)

/* [4. Custom Caliber Dimensions (Used ONLY if caliber == "Custom")] */
custom_body_dia  = 5.74;      // Cartridge case body diameter (mm)
custom_rim_dia   = 7.06;      // Cartridge rim diameter (mm)
custom_oal       = 25.40;     // Cartridge overall length (mm)
custom_rimmed    = true;      // True = tip-down stepped counterbore; False = straight bore

safe_round_count = max(1, round(round_count));

// ============================================================================
// MATERIAL OPTIMIZATION PROFILES (PLA vs PETG)
// ============================================================================
mat_specs = (filament_type == "PLA") ?
    [
        0.35,  // [0] bore_clearance (mm)
        0.28,  // [1] moving_clearance (mm)
        2.15,  // [2] hinge_pin_dia for 1.75mm filament (mm)
        1.35,  // [3] square latch strap thickness (mm)
        0.55,  // [4] latch catch undercut depth (mm)
        0.65,  // [5] round turret barb radial overhang (mm)
        7.50   // [6] round turret axle slit length (mm)
    ] :
    [
        0.45,  // [0] bore_clearance (mm)
        0.40,  // [1] moving_clearance (mm)
        2.30,  // [2] hinge_pin_dia for 1.75mm filament (mm)
        1.85,  // [3] square latch strap thickness (mm)
        0.85,  // [4] latch catch undercut depth (mm)
        0.80,  // [5] round turret barb radial overhang (mm)
        5.80   // [6] round turret axle slit length (mm)
    ];

bore_clearance   = mat_specs[0];
moving_clearance = mat_specs[1];
hinge_pin_dia    = mat_specs[2];
latch_thick      = mat_specs[3];
latch_undercut   = mat_specs[4];
barb_overhang    = mat_specs[5];
axle_slit_len    = mat_specs[6];

// ============================================================================
// CALIBER DATABASE & AUTO-DIMENSION ENGINE
// ============================================================================
cal_specs =
    (caliber == "22LR")   ? [5.74,  7.06, 25.4, true,  ".22 LR"] :
    (caliber == "22WMR")  ? [6.15,  7.47, 34.3, true,  ".22 WMR"] :
    (caliber == "17HMR")  ? [6.15,  7.47, 34.3, true,  ".17 HMR"] :
    (caliber == "9MM")    ? [9.93,  9.96, 29.7, false, "9MM LUGER"] :
    (caliber == "380ACP") ? [9.50,  9.50, 25.0, false, ".380 ACP"] :
    (caliber == "38SPL")  ? [9.63, 11.20, 39.4, true,  ".38 SPL"] :
    (caliber == "357MAG") ? [9.63, 11.20, 40.4, true,  ".357 MAG"] :
    (caliber == "45ACP")  ? [12.09, 12.19, 32.4, false, ".45 ACP"] :
    (caliber == "223REM") ? [9.58,  9.60, 57.4, false, ".223 REM"] :
                            [custom_body_dia, custom_rim_dia, custom_oal, custom_rimmed, "CUSTOM"];

body_d     = cal_specs[0];
rim_d      = cal_specs[1];
cart_oal   = cal_specs[2];
is_rimmed  = cal_specs[3];
cal_label  = cal_specs[4];

auto_sub_text = (secondary_text == "AUTO") ? str(cal_label, " โ€ข ", safe_round_count, " RDS") : secondary_text;

main_bore_d = body_d + bore_clearance;
rim_bore_d  = max(body_d, rim_d) + bore_clearance;
rim_cb_h    = is_rimmed ? 2.2 : 0.0;

pitch = max(main_bore_d + min_web_wall, rim_bore_d + 0.55);

bore_depth    = max(12.0, cart_oal - expose_tip_mm);
base_height   = floor_thick + bore_depth;
lid_headroom  = expose_tip_mm + 1.2;
lid_top_thick = 2.2;

echo(str("=== AUTO-CALCULATED SPECS [", filament_type, " | ", cal_label, " x ", safe_round_count, " rds] ==="));
echo(str("Bore Dia: ", main_bore_d, "mm | Moving Clearance: ", moving_clearance, "mm | Latch Thick: ", latch_thick, "mm"));

// ============================================================================
// SHARED HELPER FUNCTIONS & MODULES
// ============================================================================
function sum_list(v, i = 0) =
    (i >= len(v)) ? 0 : v[i] + sum_list(v, i + 1);

module cartridge_bore() {
    cylinder(d = main_bore_d, h = bore_depth + 1);
    if (is_rimmed && rim_bore_d > main_bore_d) {
        translate([0, 0, bore_depth - rim_cb_h])
        cylinder(d = rim_bore_d, h = rim_cb_h + 1);
    }
    translate([0, 0, bore_depth - 0.7])
    cylinder(d1 = rim_bore_d, d2 = rim_bore_d + 0.6, h = 0.8);
}

module bold_text_2d(str_in, size, font_name) {
    if (font_bold_offset > 0) {
        offset(delta = font_bold_offset)
        text(str_in, size = size, font = font_name, halign = "center", valign = "center");
    } else {
        text(str_in, size = size, font = font_name, halign = "center", valign = "center");
    }
}

module curved_text(str_in, radius, size, font_name, start_deg, step_deg, depth) {
    n = len(str_in);
    if (n > 0) {
        total_span = (n - 1) * step_deg;
        a0 = start_deg + total_span / 2;
        for (i = [0 : n - 1]) {
            ang = a0 - i * step_deg;
            rotate([0, 0, ang])
            translate([0, radius, 0])
            linear_extrude(height = depth)
            bold_text_2d(str_in[i], size = size, font_name = font_name);
        }
    }
}

module rounded_rect(w, d, h, r) {
    hull() {
        for (sx = [-1, 1], sy = [-1, 1]) {
            translate([sx * (w/2 - r), sy * (d/2 - r), 0])
            cylinder(r = r, h = h, $fn = 32);
        }
    }
}

// ============================================================================
// MODE A: ROUND CAPTIVE ROTATING TURRET CAN (100% SUPPORT-FREE)
// ============================================================================
safe_arc_deg = 50.0;
active_arc   = 360.0 - safe_arc_deg;
start_ang    = safe_arc_deg / 2;
hub_clear_r  = 9.5;

function ring_cap(r_idx) =
    let(rad = hub_clear_r + (r_idx - 0.5) * pitch)
    max(1, floor((active_arc * PI / 180.0 * rad) / pitch) + 1);

function total_cap_up_to(n_rings) =
    (n_rings <= 0) ? 0 : ring_cap(n_rings) + total_cap_up_to(n_rings - 1);

function solve_num_rings(target, r = 1) =
    (total_cap_up_to(r) >= target) ? r : solve_num_rings(target, r + 1);

num_rings = solve_num_rings(safe_round_count);
cap_sum   = total_cap_up_to(num_rings);

inner_ring_counts = (num_rings <= 1) ? [] : [
    for (r = [1 : num_rings - 1])
        max(1, round(safe_round_count * ring_cap(r) / cap_sum))
];

last_ring_count = max(1, safe_round_count - sum_list(inner_ring_counts));
ring_counts     = concat(inner_ring_counts, [last_ring_count]);

outer_ring_rad = hub_clear_r + (num_rings - 0.5) * pitch;
round_od       = 2 * (outer_ring_rad + rim_bore_d/2 + outer_wall_thick);
lid_skirt_h    = 7.2;

if (box_shape == "round") {
    echo(str("Round Turret OD: ", round(round_od*10)/10, "mm (", round(round_od/25.4*100)/100, " in) across ", num_rings, " rings"));
}

module scalloped_cylinder(d, h, flutes = 28, flute_r = 1.05) {
    difference() {
        cylinder(d = d, h = h);
        for (i = [0 : flutes - 1]) {
            rotate([0, 0, i * (360 / flutes)])
            translate([d/2 + flute_r*0.45, 0, -0.5])
            cylinder(r = flute_r, h = h + 1, $fn = 24);
        }
    }
}

module snap_axle_post(h_total) {
    post_r   = 4.6;
    barb_r   = post_r + barb_overhang;
    slit_w   = (filament_type == "PLA") ? 1.5 : 1.3;
    // True 45-degree underside ramp so the barb prints cleanly without supports
    ramp_h   = barb_overhang + 0.15;
    
    difference() {
        union() {
            cylinder(r = post_r, h = h_total - 2.3);
            translate([0, 0, h_total - 2.3])
            cylinder(r1 = barb_r, r2 = post_r - 0.4, h = 2.3);
            translate([0, 0, h_total - 2.3 - ramp_h])
            cylinder(r1 = post_r, r2 = barb_r, h = ramp_h);
        }
        translate([0, 0, h_total - axle_slit_len]) {
            cube([post_r*2.6, slit_w, axle_slit_len * 2], center = true);
            cube([slit_w, post_r*2.6, axle_slit_len * 2], center = true);
        }
    }
}

module round_turret_base() {
    step_od = round_od - 2.8;
    axle_h  = lid_headroom + lid_top_thick + 0.3;
    
    difference() {
        union() {
            scalloped_cylinder(d = round_od, h = base_height - lid_skirt_h);
            
            translate([0, 0, base_height - lid_skirt_h])
            cylinder(d = step_od, h = lid_skirt_h);
            
            translate([step_od/2 - 0.1, 0, base_height - lid_skirt_h/2])
            sphere(r = (filament_type == "PLA") ? 0.75 : 0.90, $fn = 20);
            
            for (a = [30 : 30 : 330]) {
                rotate([0, 0, a])
                translate([step_od/2 - 0.2, 0, base_height - lid_skirt_h/2])
                sphere(r = 0.5, $fn = 16);
            }
            
            translate([0, 0, base_height])
            snap_axle_post(h_total = axle_h);
        }
        
        for (r_idx = [0 : num_rings - 1]) {
            cnt = ring_counts[r_idx];
            rad = hub_clear_r + (r_idx + 0.5) * pitch;
            step_deg = (cnt > 1) ? (active_arc / (cnt - 1)) : 0;
            
            for (i = [0 : cnt - 1]) {
                ang = (cnt == 1) ? 180 : (start_ang + i * step_deg);
                rotate([0, 0, ang])
                translate([rad, 0, floor_thick])
                cartridge_bore();
            }
        }
        
        translate([round_od/2, 0, (base_height - lid_skirt_h)/2])
        rotate([0, 0, 45])
        cube([1.6, 1.6, base_height], center = true);
    }
}

module round_turret_lid() {
    step_id      = round_od - 2.8 + (moving_clearance * 2);
    total_lid_h  = lid_skirt_h + lid_headroom + lid_top_thick;
    hub_bore_r   = 4.6 + moving_clearance;
    barb_catch_r = 4.6 + barb_overhang + moving_clearance + 0.1;
    
    slot_r_in    = hub_clear_r + 0.5 * pitch;
    slot_r_out   = outer_ring_rad;
    slot_w_in    = rim_bore_d + 1.8;
    slot_w_out   = rim_bore_d + 3.4;
    
    difference() {
        union() {
            scalloped_cylinder(d = round_od, h = total_lid_h);
            translate([0, 0, total_lid_h - 1.2])
            cylinder(d1 = round_od, d2 = round_od - 2.2, h = 1.2);
        }
        
        translate([0, 0, -0.1])
        cylinder(d = step_id, h = lid_skirt_h + lid_headroom + 0.1);
        
        translate([step_id/2 + 0.15, 0, lid_skirt_h/2])
        sphere(r = 0.95, $fn = 20);
        
        for (a = [30 : 30 : 330]) {
            rotate([0, 0, a])
            translate([step_id/2 + 0.15, 0, lid_skirt_h/2])
            sphere(r = 0.6, $fn = 16);
        }
        
        translate([round_od/2, 0, total_lid_h/2])
        rotate([0, 0, 45])
        cube([1.6, 1.6, total_lid_h + 1], center = true);
        
        translate([0, 0, lid_skirt_h + lid_headroom - 0.5])
        hull() {
            translate([slot_r_in, 0, 0])  cylinder(d = slot_w_in,  h = lid_top_thick + 2);
            translate([slot_r_out, 0, 0]) cylinder(d = slot_w_out, h = lid_top_thick + 2);
        }
        
        translate([0, 0, total_lid_h - 0.8])
        hull() {
            translate([slot_r_in, 0, 0])  cylinder(d1 = slot_w_in,  d2 = slot_w_in + 1.6,  h = 1.0);
            translate([slot_r_out, 0, 0]) cylinder(d1 = slot_w_out, d2 = slot_w_out + 1.6, h = 1.0);
        }
        
        translate([0, 0, lid_skirt_h + lid_headroom - 0.5])
        cylinder(r = hub_bore_r, h = lid_top_thick + 2);
        
        translate([0, 0, total_lid_h - 1.4])
        cylinder(r = barb_catch_r, h = 1.6);
        
        if (show_text) {
            max_outer_r = (round_od / 2) - 4.2;
            min_inner_r = 11.2;
            
            r_text_1 = max(min_inner_r + 5.5, max_outer_r - 2.6);
            r_text_2 = max(min_inner_r + 1.0, r_text_1 - 7.5);
            
            max_span_1 = 165.0;
            max_span_2 = 145.0;
            
            n1 = max(1, len(primary_text));
            n2 = max(1, len(auto_sub_text));
            
            arc_len_1 = (r_text_1 * PI * max_span_1 / 180.0);
            arc_len_2 = (r_text_2 * PI * max_span_2 / 180.0);
            
            sz_text_1 = min(4.6, (arc_len_1 / n1) * 1.15);
            sz_text_2 = min(3.6, min(sz_text_1 * 0.82, (arc_len_2 / n2) * 1.15));
            
            step_1 = (n1 > 1) ? min(9.2, max_span_1 / (n1 - 1)) : 0;
            step_2 = (n2 > 1) ? min(9.8, max_span_2 / (n2 - 1)) : 0;
            
            rotate([0, 0, 90]) {
                translate([0, 0, total_lid_h - engrave_depth])
                curved_text(primary_text, r_text_1, sz_text_1, text_font, 0, step_1, engrave_depth + 0.15);
                
                if (r_text_2 >= min_inner_r) {
                    translate([0, 0, total_lid_h - engrave_depth])
                    curved_text(auto_sub_text, r_text_2, sz_text_2, text_font, 0, step_2, engrave_depth + 0.15);
                }
            }
        }
    }
    
    difference() {
        translate([0, 0, lid_skirt_h + lid_headroom])
        cylinder(r = 8.2, h = lid_top_thick);
        
        translate([0, 0, lid_skirt_h + lid_headroom - 0.5])
        cylinder(r = hub_bore_r, h = lid_top_thick + 2);
        
        translate([0, 0, total_lid_h - 1.4])
        cylinder(r = barb_catch_r, h = 1.6);
    }
}

// ============================================================================
// MODE B: SQUARE HINGED CLAMSHELL BOX (100% SUPPORT-FREE TEARDROP HINGES)
// ============================================================================
function grid_score(n, r) =
    let(
        c = ceil(n / r),
        waste = (c * r) - n,
        aspect = c / r
    )
    (waste * 12) + abs(aspect - 1.45) * 4 + (aspect > 2.25 ? 50 : 0) + (c < r ? 20 : 0);

function best_row_count(n, r = 2, best_r = 2) =
    (r > max(2, ceil(sqrt(n)) + 2)) ? best_r :
    best_row_count(n, r + 1, (grid_score(n, r) < grid_score(n, best_r)) ? r : best_r);

sq_rows = (safe_round_count <= 3) ? 1 : best_row_count(safe_round_count);
sq_cols = max(1, ceil(safe_round_count / sq_rows));

base_per_row = floor(safe_round_count / sq_rows);
extra_holes  = safe_round_count % sq_rows;
row_counts   = [
    for (r = [0 : sq_rows - 1])
        base_per_row + (r < extra_holes ? 1 : 0)
];

sq_inner_w  = (sq_cols * pitch) + 1.6;
sq_inner_d  = (sq_rows * pitch) + 1.6;
sq_box_w    = sq_inner_w + 2 * outer_wall_thick;
sq_box_d    = sq_inner_d + 2 * outer_wall_thick;
sq_corner_r = 4.2;

sq_lip_h    = 2.6;
sq_lid_h    = lid_headroom + lid_top_thick;

hinge_r     = 3.4;
hinge_y     = sq_box_d/2 + hinge_r - 0.6;
hinge_z     = base_height;
hinge_span  = min(sq_box_w - 14.0, max(24.0, sq_box_w * 0.62));
knuckle_w   = hinge_span / 3.0;

latch_w     = min(26.0, max(16.0, sq_box_w * 0.34));

if (box_shape == "square") {
    echo(str("Square Hinged Box: ", round(sq_box_w*10)/10, "mm W x ", round(sq_box_d*10)/10, "mm D x ", round((base_height + sq_lid_h)*10)/10, "mm H (", sq_cols, " cols x ", sq_rows, " rows | Row counts: ", row_counts, ")"));
}

// Support-free 45-deg gusseted hinge barrel (eliminates steep bottom overhang)
module support_free_hinge_knuckle(len_x, attach_y_sign = -1, drop_z_dir = -1) {
    hull() {
        rotate([0, 90, 0])
        cylinder(r = hinge_r, h = len_x, center = true, $fn = 36);
        
        // 45-degree sloped gusset back into the box wall so zero supports are needed
        translate([0, attach_y_sign * (hinge_r - 0.4), drop_z_dir * (hinge_r * 1.15)])
        cube([len_x, 0.4, 0.4], center = true);
        
        translate([0, attach_y_sign * (hinge_r - 0.4), 0])
        cube([len_x, 0.4, hinge_r * 1.6], center = true);
    }
}

// Teardrop horizontal bore so the 2.2mm pin hole prints round with zero top-sag
module teardrop_pin_bore(dia, len_x) {
    r = dia / 2;
    rotate([0, 90, 0])
    linear_extrude(height = len_x, center = true)
    polygon([
        for (a = [0 : 15 : 345]) [r * cos(a), r * sin(a)],
        [r * 1.25, 0] // Pointed apex oriented along +Z when rotated [0,90,0]
    ]);
}

module square_hinged_base() {
    lip_wall = 1.2;
    
    difference() {
        union() {
            rounded_rect(sq_box_w, sq_box_d, base_height, sq_corner_r);
            
            translate([0, 0, base_height - 0.2])
            difference() {
                rounded_rect(sq_inner_w + lip_wall*2, sq_inner_d + lip_wall*2, sq_lip_h + 0.2, 2.4);
                translate([0, 0, -0.5])
                rounded_rect(sq_inner_w, sq_inner_d, sq_lip_h + 1.5, 1.8);
            }
            
            // Outer 2 Support-Free Hinge Knuckles on rear wall (+Y)
            for (sx = [-1, 1]) {
                translate([sx * knuckle_w, hinge_y, hinge_z])
                support_free_hinge_knuckle(knuckle_w - moving_clearance, attach_y_sign = -1, drop_z_dir = -1);
            }
            
            // 45-degree Self-Supporting Front Catch Lug on front wall (-Y)
            translate([0, -sq_box_d/2, base_height - 4.4])
            hull() {
                // Wide vertical root on wall
                translate([0, 0.2, -1.2])
                cube([latch_w - 2.0, 0.4, 5.2], center = true);
                
                // Catch tooth with 45-deg underside slope (zero overhang droop)
                translate([0, -0.4 - latch_undercut, 0.6])
                cube([latch_w - 2.6, 1.0, 1.4], center = true);
            }
        }
        
        // Symmetrical row-by-row hole placement
        y0 = -((sq_rows - 1) * pitch) / 2;
        for (r = [0 : sq_rows - 1]) {
            cols_in_this_row = row_counts[r];
            x0_row = -((cols_in_this_row - 1) * pitch) / 2;
            for (c = [0 : cols_in_this_row - 1]) {
                translate([x0_row + c * pitch, y0 + r * pitch, floor_thick])
                cartridge_bore();
            }
        }
        
        // Teardrop through-bore for 1.75mm filament hinge pin
        translate([0, hinge_y, hinge_z])
        teardrop_pin_bore(dia = hinge_pin_dia, len_x = hinge_span + 6);
    }
}

module square_hinged_lid() {
    lip_wall   = 1.2 + moving_clearance;
    strap_drop = (filament_type == "PLA") ? 9.8 : 8.6;
    
    difference() {
        union() {
            rounded_rect(sq_box_w, sq_box_d, sq_lid_h, sq_corner_r);
            
            translate([0, 0, sq_lid_h - 1.0])
            hull() {
                rounded_rect(sq_box_w, sq_box_d, 0.1, sq_corner_r);
                translate([0, 0, 1.0])
                rounded_rect(sq_box_w - 2.0, sq_box_d - 2.0, 0.1, sq_corner_r - 0.8);
            }
            
            // Center Support-Free Hinge Knuckle on rear wall (+Y)
            // Note: lid prints upside-down (rotated 180 around X), so +Z here becomes -Z on build plate!
            translate([0, hinge_y, 0])
            support_free_hinge_knuckle(knuckle_w - moving_clearance, attach_y_sign = -1, drop_z_dir = 1);
            
            // Flexible Snap-Latch Tab (-Y) - prints vertically upward when lid is flipped
            translate([0, -sq_box_d/2 - latch_thick/2 - 0.15, 0])
            difference() {
                union() {
                    translate([0, 0, (sq_lid_h - strap_drop)/2])
                    cube([latch_w, latch_thick, sq_lid_h + strap_drop - 1.5], center = true);
                    
                    translate([0, -latch_thick/2 - 0.6, -strap_drop + 1.8])
                    rotate([0, 90, 0])
                    cylinder(r = 1.4, h = latch_w, center = true, $fn = 20);
                }
                translate([0, latch_thick/2 + 0.2, -4.0])
                cube([latch_w - 1.2, latch_undercut * 2 + 0.6, 2.2], center = true);
            }
        }
        
        translate([0, 0, -0.1])
        rounded_rect(sq_inner_w, sq_inner_d, lid_headroom + 0.1, 1.8);
        
        translate([0, 0, -0.1])
        rounded_rect(sq_inner_w + lip_wall*2, sq_inner_d + lip_wall*2, sq_lip_h + moving_clearance + 0.1, 2.5);
        
        // Teardrop hinge pin through-hole (apex oriented for inverted lid print orientation)
        translate([0, hinge_y, 0])
        rotate([180, 0, 0])
        teardrop_pin_bore(dia = hinge_pin_dia, len_x = knuckle_w + 4);
        
        if (show_text) {
            safe_txt_w = sq_box_w - 10.0;
            safe_txt_d = sq_box_d - 10.0;
            
            n1 = max(1, len(primary_text));
            n2 = max(1, len(auto_sub_text));
            
            sz_1_w = safe_txt_w / (n1 * 0.82);
            sz_2_w = safe_txt_w / (n2 * 0.82);
            
            sz_1 = min(6.2, min(sz_1_w, safe_txt_d * 0.24));
            sz_2 = min(4.4, min(sz_2_w, min(sz_1 * 0.78, safe_txt_d * 0.18)));
            
            y_off = max(sz_1 * 0.75, safe_txt_d * 0.18);
            
            translate([0, y_off, sq_lid_h - engrave_depth])
            linear_extrude(height = engrave_depth + 0.15)
            bold_text_2d(primary_text, size = sz_1, font_name = text_font);
            
            translate([0, -y_off, sq_lid_h - engrave_depth])
            linear_extrude(height = engrave_depth + 0.15)
            bold_text_2d(auto_sub_text, size = sz_2, font_name = text_font);
        }
    }
}

// ============================================================================
// BUILD PLATE RENDER LAYOUT (AUTO-ORIENTED FOR 100% SUPPORT-FREE PRINTING)
// ============================================================================
if (box_shape == "round") {
    if (render_part == "base") {
        round_turret_base();
    } else if (render_part == "lid") {
        translate([0, 0, lid_skirt_h + lid_headroom + lid_top_thick])
        rotate([180, 0, 0])
        round_turret_lid();
    } else {
        translate([-round_od/2 - 5, 0, 0])
        round_turret_base();
        
        translate([round_od/2 + 5, 0, lid_skirt_h + lid_headroom + lid_top_thick])
        rotate([180, 0, 0])
        round_turret_lid();
    }
} else {
    if (render_part == "base") {
        square_hinged_base();
    } else if (render_part == "lid") {
        translate([0, 0, sq_lid_h])
        rotate([180, 0, 0])
        square_hinged_lid();
    } else {
        translate([-sq_box_w/2 - 6, 0, 0])
        square_hinged_base();
        
        translate([sq_box_w/2 + 6, 0, sq_lid_h])
        rotate([180, 0, 0])
        square_hinged_lid();
    }
}