Skip to content

Instantly share code, notes, and snippets.

@ianhays
Created August 27, 2026 13:13
Show Gist options
  • Select an option

  • Save ianhays/c79562685988f0b06b180b0de077db27 to your computer and use it in GitHub Desktop.

Select an option

Save ianhays/c79562685988f0b06b180b0de077db27 to your computer and use it in GitHub Desktop.
boxgen
// ====================================================================
// Configuration Panel Variables
// ====================================================================
/* [Globals] */
$fn = 60;
global_laser_kerf = 0.10; // Laser kerf adjustment amount
global_tab_tightening = 0.25; // Friction-fit snugness modifier added directly to male tabs to tighten lookups (mm)
mat_thickness = 3.0; // Panel material thickness (mm)
/* [View & Export Controls] */
DEPLOYMENT_MODE = "3D_BOX"; // ["3D_BOX", "ALL_LAYERS_PREVIEW", "EXPORT_CUTS_ONLY", "EXPORT_RASTERS_ONLY", "EXPORT_TEXT_ONLY", "EXPORT_MOUNTING"]
DEPLOYMENT_LAYOUT = "assembly"; // ["assembly", "print"]
padding = 5.0; // Padding between parts on sheet (mm)
/* [Unit Dimensions: 1 unit is 101mm exterior] */
box_units_w = 1.5; // Clean interior width (units)- 101*units - 2*thickness
box_units_h = 1.5; // Clean interior height (units)
box_units_d = 0.5; // Clean interior depth (unitsc)
/* [Door Configuration] */
// Mechanical style of the front door enclosure
door_system_type = "sliding"; // ["sliding", "hinged", "none"]
door_thickness = 3.0; // Thickness of clear acrylic door panel (mm)
door_include_thumb_hole = true; // Toggle whether the door includes a pull handle cutout
door_thumb_hole_offset = 12.0; // Distance to lower the thumb hole center down away from the top edge (mcm)
sliding_door_clearance = 0.3; // Track clearance wiggle room (mm)
sliding_track_raster_depth = 1.0; // Depth of the rastered channels into the sidewalls
/* [Modular Connection Port Configuration] */
port_include_left = true; // Punch out a modular connection port through the Left Side Wall
port_include_right = true; // Punch out a modular connection port through the Right Side Wall
port_include_floor = false; // Punch out a modular connection port through the Box Floor panel
port_include_ceiling = true; // Punch out a modular connection port through the Top Ceiling panel
port_width = 5.0;
port_height = 10.0;
port_shape_sides = "rectangle"; // ["rectangle", "circle"]
port_shape_floor = "rectangle"; // ["rectangle", "circle"]
port_shape_ceiling = "rectangle"; // ["rectangle", "circle"]
/* [Advanced: Tab Connector Options] */
tabs_include_sides = true; // Toggle interlocking tab joints between the side walls and floor/ceiling panels
tabs_count_per_edge = 4; // Number of interlocking tab joints to space evenly along each connecting panel edge
/* [Advanced: Mounting Rail - Box Slot Configuration] */
mount_rail_vertical_offset = -24.9; // Vertical displacement shift of the rail tracking cutout away from dead center (mm)
/* [Advanced: Mounting Rail - Wall Rail Configuration] */
mount_rail_length = 609.6; // Total horizontal width of the wall rail bracket track (mm)
mount_rail_height = 35.0; // Vertical height of the base plate and front cap lips (Layers 1 & 3) (mm)
mount_rail_node_height = 25.0; // Vertical height of the inner neck spacer channel (Layer 2) (mm)
mount_rail_node_width = 25.0; // Horizontal width of the locking node islands / standing land tabs (mm)
mount_rail_node_spacing = 67.0; // Fixed horizontal step interval between lock/key seating nodes (mm)
mount_rail_node_justification = "CENTER"; // ["CENTER", "LEFT"]
mount_rail_half_node_endpoints = true; // Force half-nodes at both ends of the rail to seamlessly stitch tiled tracks together
/* [Advanced: Mounting Rail - Lock Key Configuration] */
mount_key_extra_top = 10.0; // Additional height to add to the top bar section of the key (mm)
mount_key_extra_leg = 5.0; // Additional height to add to the legs of the key (mm)
include_key_thumb_hole = true; // Toggle whether the locking keys include a finger grab cutout on their top section
mount_include_alignment_pegs = true; // Toggle whether the mounting sheet exports interlocking wood alignment pegs
/* [Debug: Labels] */
labels_include = false; // Burn labels onto panels
labels_text_size = 6.0; // Height of font text in mm
// ====================================================================
// Static internal variables
// ====================================================================
// Internal mm dimensions
box_inner_w = (101*box_units_w)-(2*mat_thickness); // Clean interior width (mm
box_inner_h = (101*box_units_h)-(2*mat_thickness); // Clean interior height (mm)
box_inner_d = (101*box_units_d)-(2*mat_thickness); // Clean interior depth (mm)
// Global static offset and boundary definitions
k_offset = global_laser_kerf / 2;
door_track_w = door_thickness + sliding_door_clearance;
back_w = box_inner_w + (mat_thickness * 2);
back_h = box_inner_h + (mat_thickness * 2);
side_w = box_inner_d + mat_thickness;
side_h = box_inner_h + (mat_thickness * 2);
floor_w = box_inner_w;
floor_h = box_inner_d + mat_thickness;
door_w = box_inner_w + (sliding_track_raster_depth * 2) - sliding_door_clearance;
door_h = box_inner_h + sliding_track_raster_depth - sliding_door_clearance + mat_thickness;
h_top = (door_system_type == "sliding") ? (box_inner_d + mat_thickness - door_track_w - mat_thickness) : floor_h;
thumb_d = min(25.0, (mount_key_extra_top+mount_rail_height-mount_rail_node_height)/2);
// --- MASTER ROUTER CONTROL ---
if (DEPLOYMENT_MODE == "3D_BOX") {
assembled_3d_preview();
} else if (DEPLOYMENT_MODE == "ALL_LAYERS_PREVIEW") {
flat_laser_sheet_core("ALL");
} else if (DEPLOYMENT_MODE == "EXPORT_CUTS_ONLY") {
flat_laser_sheet_core("CUTS");
} else if (DEPLOYMENT_MODE == "EXPORT_RASTERS_ONLY") {
flat_laser_sheet_core("RASTERS");
} else if (DEPLOYMENT_MODE == "EXPORT_TEXT_ONLY") {
flat_laser_sheet_core("TEXT");
} else if (DEPLOYMENT_MODE == "EXPORT_MOUNTING") {
flat_secure_rail_sheet();
}
// ====================================================================
// PARAMETRIC COMPONENT MODULES
// ====================================================================
module panel_back_master_2d(layer) {
if (layer == "CUTS" || layer == "ALL") {
color("Red") difference() {
square([back_w, back_h], center = true);
// Add 0.1 to make sure the outer wall is killed all the way and doesnt leave a teensy strip of leftover wall.
// Female Tabs - Left & Right Sides
if (tabs_count_per_edge > 0) {
safe_margin_h = back_h / ((tabs_count_per_edge * 2) + 1);
for (i = [0 : tabs_count_per_edge - 1]) {
y_local_center = (2 * i + 1) * safe_margin_h;
y_tab = -back_h/2 + y_local_center;
// Left vertical edge slots
translate([-back_w/2-0.1, y_tab - safe_margin_h/2 + k_offset])
square([mat_thickness+0.1, safe_margin_h - global_laser_kerf]);
// Right vertical edge slots
translate([back_w/2 - mat_thickness, y_tab - safe_margin_h/2 + k_offset])
square([mat_thickness+0.1, safe_margin_h - global_laser_kerf]);
}
}
// Female Tabs - Ceiling & Floor
if (tabs_count_per_edge > 0) {
safe_margin_fw = floor_w / ((tabs_count_per_edge * 2) + 1);
for (i = [0 : tabs_count_per_edge - 1]) {
x_local_center = (2 * i + 1) * safe_margin_fw;
x_tab = -floor_w/2 + x_local_center;
// Bottom horizontal edge slots
translate([x_tab - safe_margin_fw /2 + k_offset, -back_h/2-0.1])
square([safe_margin_fw - global_laser_kerf, mat_thickness+0.1]);
// Top horizontal edge slots
translate([x_tab - safe_margin_fw /2 + k_offset, back_h/2 - mat_thickness])
square([safe_margin_fw - global_laser_kerf, mat_thickness+0.1]);
}
}
// MODULAR RAIL PASS-THROUGH GATEWAY SLOT
translate([-back_w/2 - k_offset, -mount_rail_height/2 - k_offset + mount_rail_vertical_offset])
square([back_w + global_laser_kerf, mount_rail_height + global_laser_kerf]);
}
}
if (labels_include && (layer == "TEXT" || layer == "ALL")) {
color("Black") text("SOLID BACK", size = labels_text_size, font = "Liberation Sans:style=Bold", halign = "center", valign = "center");
}
}
module generic_wall_2d(name, layer, is_right=false) {
if (layer == "CUTS" || layer == "ALL") {
color("Red") difference() {
// Main wall body + MALE REAR TABS
union() {
square([side_w, side_h]);
// MALE BACK TABS: Securely spaced within safe edge-margin boundaries
if (tabs_count_per_edge > 0) {
safe_margin = side_h / ((tabs_count_per_edge * 2) + 1);
for (i = [0 : tabs_count_per_edge - 1]) {
// Centers the tab exactly over the odd-numbered segment slices
y_tab = (2 * i + 1) * safe_margin;
translate([-mat_thickness, y_tab - (safe_margin + global_tab_tightening)/2 - k_offset])
square([mat_thickness, safe_margin + global_tab_tightening + global_laser_kerf]);
}
}
}
// Female Corner Tabs
if (tabs_include_sides && tabs_count_per_edge > 0) {
safe_margin_w = side_w / ((tabs_count_per_edge * 2) + 1);
for (i = [0 : tabs_count_per_edge - 1]) {
x_tab = (2 * i + 1) * safe_margin_w;
translate([x_tab - safe_margin_w/2 + k_offset, -0.1])
square([safe_margin_w - global_laser_kerf, mat_thickness+0.1]);
translate([x_tab - safe_margin_w/2 + k_offset, side_h - mat_thickness])
square([safe_margin_w - global_laser_kerf, mat_thickness+0.1]);
}
}
// MODULAR MOUNT SIDE CLEARANCE CUTOUT (DEAD-CENTERED)
translate([-10, (side_h/2) - mount_rail_height/2 - k_offset + mount_rail_vertical_offset])
square([mat_thickness * 2 + 10, mount_rail_height + global_laser_kerf]);
// MODULAR CONNECTOR GRID PORT HOLE (SIDE WALLS)
if ((name == "LEFT WALL" && port_include_left) || (name == "RIGHT WALL" && port_include_right)) {
if (port_shape_floor == "rectangle")
translate([(side_w / 2) - (port_width / 2) - k_offset, (side_h / 2) - (port_height / 2) - k_offset])
square([port_width + global_laser_kerf, port_height + global_laser_kerf]);
if (port_shape_floor == "circle")
translate([(side_w / 2) - k_offset, (side_h / 2) - k_offset])
circle(d = port_width + global_laser_kerf);
}
}
}
// ====================================================================
// INTEGRATED DOOR SYSTEM CUTOUTS (SIDE WALL MARGINS)
// ====================================================================
if (door_system_type == "sliding" && (layer == "RASTERS" || layer == "ALL")) {
// Track height runs completely through the top edge margin
color("Yellow")
translate([side_w - mat_thickness - door_track_w, mat_thickness - 1.0])
square([door_track_w, side_h - mat_thickness + 2.0]);
}
if (labels_include && (layer == "TEXT" || layer == "ALL")) {
color("Black") translate([side_w/2, side_h/2]) rotate([0, 0, is_right ? -90 : 90])
text(name, size = labels_text_size, font = "Liberation Sans:style=Bold", halign = "center", valign = "center");
}
}
module generic_horizontal_2d(name, current_h, layer, is_floor=false) {
if (layer == "CUTS" || layer == "ALL") {
color("Red") {
difference () {
// Main body + MALE REAR TABS + FIXED CORNER TABS
union() {
// Main Body
square([floor_w, current_h]);
// Male Rear Tabs
if (tabs_count_per_edge > 0) {
safe_margin_fw = floor_w / ((tabs_count_per_edge * 2) + 1);
for (i = [0 : tabs_count_per_edge - 1]) {
x_tab = (2 * i + 1) * safe_margin_fw;
translate([x_tab - (safe_margin_fw + global_tab_tightening)/2 - k_offset, -mat_thickness])
square([safe_margin_fw + global_tab_tightening + global_laser_kerf, mat_thickness]);
}
}
// Male Corner Tabs
if (tabs_include_sides && tabs_count_per_edge > 0) {
safe_margin_w = side_w / ((tabs_count_per_edge * 2) + 1);
for (i = [0 : tabs_count_per_edge - 1]) {
y_tab = (2 * i + 1) * safe_margin_w;
if (y_tab < current_h - safe_margin_w/2) {
translate([-mat_thickness, y_tab - (safe_margin_w + global_tab_tightening)/2 - k_offset])
square([mat_thickness, (safe_margin_w + global_tab_tightening) + global_laser_kerf]);
translate([floor_w, y_tab - (safe_margin_w + global_tab_tightening)/2 - k_offset])
square([mat_thickness, (safe_margin_w + global_tab_tightening) + global_laser_kerf]);
}
}
}
}
// ====================================================================
// SAFE PIN-HINGE ROTATION SOCKET (FLOOR / CEILING)
// ====================================================================
// Shifted inward away from the outer edge lines to prevent blowout,
// leaving a solid wood wall margin around the 4.5mm hole path.
if (door_system_type == "hinged") {
pivot_x = mat_thickness + 3.0;
pivot_y = current_h - mat_thickness;
translate([pivot_x, pivot_y])
circle(d = 4.5 + global_laser_kerf);
}
// MODULAR CONNECTOR GRID PORT HOLE (FLOOR)
if (name == "BOX FLOOR" && port_include_floor) {
if (port_shape_floor == "rectangle")
translate([(floor_w / 2) - (port_height / 2) - k_offset, (current_h / 2) - (port_width / 2) - k_offset])
square([port_height + global_laser_kerf, port_width + global_laser_kerf]);
if (port_shape_floor == "circle")
translate([(floor_w / 2) - k_offset, (current_h / 2) - k_offset])
circle(d = port_width + global_laser_kerf);
}
// MODULAR CONNECTOR GRID PORT HOLE (CEILING)
if (name == "TOP CEILING" && port_include_ceiling) {
if (port_shape_ceiling == "rectangle")
translate([(floor_w / 2) - (port_height / 2) - k_offset, (current_h / 2) - (port_width / 2) - k_offset])
square([port_height + global_laser_kerf, port_width + global_laser_kerf]);
if (port_shape_floor == "circle")
translate([(floor_w / 2) - k_offset, (current_h / 2) - k_offset])
circle(d = port_width + global_laser_kerf);
}
}
}
}
if (is_floor && (door_system_type == "sliding") && (layer == "RASTERS" || layer == "ALL")) {
color("Blue") translate([-1.0, current_h - mat_thickness - door_track_w])
square([floor_w + 2.0, door_track_w]);
}
if (labels_include && (layer == "TEXT" || layer == "ALL")) {
color("Black") translate([floor_w/2, current_h/2])
text(name, size = labels_text_size, font = "Liberation Sans:style=Bold", halign = "center", valign = "center");
}
}
module clear_door_panel_2d(layer) {
if (layer == "CUTS" || layer == "ALL") {
color("SkyBlue") {
difference() {
// --- MASTER ENVELOPE SELECTION TREE ---
if (door_system_type == "sliding") {
// STYLE A: Horizontal Sliding Track Panel
square([door_w, door_h], center = true);
} else if (door_system_type == "hinged") {
// STYLE B: Recessed Interior Swing Gate Profile
// Sized to fit cleanly with clearance inside the box inner opening frame
hinge_door_w = box_inner_w - sliding_door_clearance * 2;
hinge_door_h = box_inner_h - sliding_door_clearance * 2;
slim_pin_w = 3;
union() {
// 1. Core Door Pane (Clean centered layout)
square([hinge_door_w, hinge_door_h], center = true);
// 2. RECESSED HINGE PINS (Top & Bottom Edge Vertical Protrusions)
// Measured from the left edge of the door pane to match the 3mm hole recess
pin_local_x = -hinge_door_w / 2 + mat_thickness + 3.0 - slim_pin_w / 2 -sliding_door_clearance;
// Top Pin (Extends vertically up into the ceiling)
translate([pin_local_x, hinge_door_h / 2])
square([slim_pin_w, mat_thickness]);
// Bottom Pin (Extends vertically down into the floor)
translate([pin_local_x, -hinge_door_h / 2 - mat_thickness])
square([slim_pin_w, mat_thickness]);
}
}
// --- ERGONOMIC THUMB HOLE PULL SYSTEM (VERTICALLY CENTERED FOR HINGED) ---
if (door_include_thumb_hole) {
// Coordinates dynamically map based on your active mechanical enclosure profile
y_offset = (door_system_type == "sliding") ?
(door_h / 2 - door_thumb_hole_offset) :
0.0; // FIXED: Drops the hole right onto the horizontal midpoint axis
x_offset = (door_system_type == "sliding") ? 0.0 :
((box_inner_w - sliding_door_clearance * 2) / 2 - door_thumb_hole_offset);
translate([x_offset, y_offset])
circle(d = 15.0);
}
}
}
}
if (labels_include && (layer == "TEXT" || layer == "ALL")) {
color("Black") text("CLEAR DOOR", size = labels_text_size, font = "Liberation Sans:style=Bold", halign = "center", valign = "center");
}
}
// ====================================================================
// WORKSPACE STAGING GRID LAYOUT (With Global Homing Anchors)
// ====================================================================
module flat_laser_sheet_core(layer) {
if (DEPLOYMENT_LAYOUT == "assembly") {
// GLOBAL HOMING ANCHOR: Places an identical 1x1mm square in the absolute top-left and bottom-right
homing_x = -(back_w/2 + side_w + padding + mat_thickness + padding);
homing_y = (back_h/2 + back_h + padding * 2);
color("Purple") translate([homing_x, homing_y]) square([1, 1]);
door_origin_x = back_w + padding + side_w + padding;
absolute_max_x = door_include_sliding_front ? (door_origin_x + door_w / 2) : (back_w / 2 + side_w + padding);
homing_br_x = absolute_max_x + padding;
homing_br_y = -(back_h / 2 + h_top + padding + mat_thickness + padding);
color("Purple") translate([homing_br_x, homing_br_y]) square([1, 1]);
panel_back_master_2d(layer);
translate([back_w/2 + padding + mat_thickness, -side_h/2])
generic_wall_2d("LEFT WALL", layer, false);
translate([-(back_w/2 + padding), -side_h/2])
mirror([1, 0, 0])
generic_wall_2d("RIGHT WALL", layer, true);
translate([-floor_w/2, back_h/2 + padding + mat_thickness])
generic_horizontal_2d("BOX FLOOR", floor_h, layer, true);
translate([-floor_w/2, -(back_h/2 + h_top + padding + mat_thickness)])
generic_horizontal_2d("TOP CEILING", h_top, layer, false);
if (door_include_sliding_front) {
translate([back_w + padding + side_w + padding, 0]) clear_door_panel_2d(layer);
}
} else {
// GLOBAL HOMING ANCHOR: Places an identical 1x1mm square in the absolute top-left and bottom-right
homing_x = -(back_w/2 + side_w + padding + mat_thickness + padding);
homing_y = (back_h*3/2 + back_h + padding * 2);
color("Purple") translate([homing_x, homing_y]) square([1, 1]);
door_origin_x = back_w + padding + side_w + padding;
absolute_max_x = (door_system_type != "none") ? (door_origin_x + door_w / 2) : (back_w / 2 + side_w + padding);
homing_br_x = absolute_max_x + padding;
homing_br_y = -(back_h / 2 + h_top + padding + mat_thickness + padding);
color("Purple") translate([homing_br_x, homing_br_y]) square([1, 1]);
panel_back_master_2d(layer);
rotate([0, 0, 180])
translate([-back_w/2 - side_w - padding, -side_h/2])
generic_wall_2d("LEFT WALL", layer, false);
translate([+back_w/2 + side_w + padding,side_h/2 + padding])
mirror([1, 0])
generic_wall_2d("RIGHT WALL", layer, true);
translate([-(floor_w / 2), (back_h / 2) + padding])
generic_horizontal_2d("BOX FLOOR", floor_h, layer, true);
translate([-(floor_w / 2), (back_h / 2) + padding + floor_h + padding])
generic_horizontal_2d("TOP CEILING", h_top, layer, false);
if (door_system_type != "none") {
translate([0, (-back_h/2)-(door_h/2)-padding])
clear_door_panel_2d(layer);
}
// --- CALIBRATED NESTING HOMING SQUARE (BOTTOM RIGHT) ---
print_max_x = (door_system_type != "none") ? (back_w + padding + side_w + padding + side_w + padding + door_w) : ((back_w / 2) + padding + side_w + padding + side_w);
color("Red") translate([print_max_x + padding, -(side_h / 2) - padding]) square();
}
}
// ====================================================================
// SECURE MOUNT SYSTEM: MODULAR STRAIGHT-IN T-RAIL & SEGMENTED KEYS
// ====================================================================
module flat_secure_rail_sheet() {
local_back_w = box_inner_w + (mat_thickness * 2);
local_side_w = box_inner_d + mat_thickness;
local_back_h = box_inner_h + (mat_thickness * 2);
// --- SYNCHRONIZED PARM MATRIX (UPDATED CONFIG VARIABLES) ---
slot_h = mount_rail_node_height;
key_top_bar_h = (mount_rail_height - mount_rail_node_height) + mount_key_extra_top;
calculated_key_h = slot_h + mount_key_extra_leg + key_top_bar_h;
calculated_key_w = mount_rail_node_width + (mount_rail_node_spacing - mount_rail_node_width) - (2 * sliding_door_clearance);
// --- DYNAMIC EDGE-STITCHING MATRIX LOGIC (FIXED RIGHT-SIDE DRIFT) ---
// Computes the number of interior spacing spans between the two absolute rail endpoints
calc_spans = floor(mount_rail_length / mount_rail_node_spacing);
safe_spans = calc_spans > 0 ? calc_spans : 1;
// LOCKED STEP: Adjusts pitch dynamically to force the last node to land exactly on the edge
active_spacing = mount_rail_half_node_endpoints ? (mount_rail_length / safe_spans) : mount_rail_node_spacing;
calc_nodes_raw = floor(mount_rail_length / active_spacing);
calc_safe_cnt = calc_nodes_raw > 0 ? calc_nodes_raw : 1;
calc_total_sp = (calc_safe_cnt - 1) * active_spacing;
safe_count = mount_rail_half_node_endpoints ? (safe_spans + 1) : calc_safe_cnt;
start_offset = mount_rail_half_node_endpoints ? 0.0 :
((mount_rail_node_justification == "CENTER") ? ((mount_rail_length - calc_total_sp) / 2) : (active_spacing / 2));
shared_hole_y = mount_rail_node_height / 2;
// --- PART A: GLOBAL COORDINATE REGISTRATION HOMING ANCHOR ---
homing_x = -(local_back_w/2 + local_side_w + padding + mat_thickness + padding);
homing_y = (back_h/2 + back_h + padding * 2);
color("Red") translate([homing_x, homing_y]) square();
// --- SECOND GLOBAL REGISTRATION HOMING ANCHOR (BOTTOM RIGHT) ---
// FIXED MATRIX: Safely tracks the maximum width boundary of the locking keys column
homing_br_rail_x = mount_rail_length + padding + calculated_key_w + padding;
homing_br_rail_y = -(local_back_h / 2) - padding;
color("Red") translate([homing_br_rail_x, homing_br_rail_y]) square();
// --- PART B: THE HARDWARE CANVAS SHEET LAYOUT ---
translate([-(local_back_w/2), -local_back_h/2]) {
// LAYER 1: Drywall Base Plate (Holes dynamically adjusted to stay full circles inside half-nodes)
color("Red") difference() {
square([mount_rail_length, mount_rail_height]);
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
// FULL-CIRCLE ENDPOINT SHIFT: Pulls edge holes inward to center on the 25mm half-nodes
x_node = (!mount_rail_half_node_endpoints) ? x_node_raw :
(i == 0) ? (mount_rail_node_width / 4) :
(i == safe_count - 1) ? (mount_rail_length - (mount_rail_node_width / 4)) : x_node_raw;
if (x_node >= 0 && x_node <= mount_rail_length) {
translate([x_node, shared_hole_y])
circle(d = 4.5);
}
}
}
// LAYER 2: The SINGLE Segmented Neck Spacer Pods
translate([0, mount_rail_height + padding])
color("Red") difference() {
intersection() {
square([mount_rail_length, mount_rail_node_height]);
union() {
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
if (x_node_raw >= 0 && x_node_raw <= mount_rail_length) {
translate([x_node_raw - mount_rail_node_width/2, 0])
square([mount_rail_node_width, mount_rail_node_height]);
}
}
}
}
// FIXED BOUNDS: Drills completely intact full-circle holes centered on the half-node material
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
x_node = (!mount_rail_half_node_endpoints) ? x_node_raw :
(i == 0) ? (mount_rail_node_width / 4) :
(i == safe_count - 1) ? (mount_rail_length - (mount_rail_node_width / 4)) : x_node_raw;
if (x_node >= 0 && x_node <= mount_rail_length) {
translate([x_node, shared_hole_y]) circle(d = 4.5);
}
}
}
// LAYER 3: Forward Overhanging T-Cap Lip
translate([0, mount_rail_height + padding + mount_rail_node_height + padding])
color("Red") difference() {
square([mount_rail_length, mount_rail_height]);
// SCREW HOLES: Slide inward to center on the half-node material lands [INDEX]
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
x_node = (!mount_rail_half_node_endpoints) ? x_node_raw :
(i == 0) ? (mount_rail_node_width / 4) :
(i == safe_count - 1) ? (mount_rail_length - (mount_rail_node_width / 4)) : x_node_raw;
if (x_node >= 0 && x_node <= mount_rail_length) {
translate([x_node, shared_hole_y])
circle(d = 4.5);
}
}
// RESTORED SCREW HEAD RELIEFS: Locked directly to the endpoints (X=0 and X=max) [INDEX]
// This guarantees they stitch into a single clean half-circle when rails are butted together [INDEX].
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
if (x_node_raw >= 0 && x_node_raw <= mount_rail_length) {
translate([x_node_raw, mount_rail_height])
circle(d = thumb_d + (thumb_d*0.1));
}
}
}
// ====================================================================
// 2. INTERNAL LOCKING KEYS (SIDE-BY-SIDE U-KEY & T-KEY PRODUCTION GRID)
// ====================================================================
// Splits your node array down the middle to export BOTH styles simultaneously
// on a single sheet pass without adding any new parameters.
key_count = floor((mount_rail_length - mount_rail_node_spacing) / mount_rail_node_spacing) + 1;
safe_keys = max(2, key_count);
for(key_idx = [0 : safe_keys - 1]) {
// Evaluates whether the current key row sits in the first or second half of the loop
is_t_key = (key_idx >= safe_keys / 2);
translate([mount_rail_length + padding, key_idx * (calculated_key_h + padding)]) {
color("Red") difference() {
// Base handle square envelope shared symmetrically between both styles
square([calculated_key_w, calculated_key_h]);
if (!is_t_key) {
// STYLE A (First Half): Traditional Open-Ended Fork Pocket Cutout
slot_top_w = mount_rail_node_width + global_laser_kerf;
slot_bot_w = mount_rail_node_width + global_laser_kerf + 1.2;
translate([calculated_key_w/2, 0])
polygon(points=[
[-slot_bot_w/2, -1],
[-slot_top_w/2, mount_key_extra_leg + slot_h],
[slot_top_w/2, mount_key_extra_leg + slot_h],
[slot_bot_w/2, -1]
]);
} else {
// STYLE B (Second Half): Dual Winged T-Key Step-Shoulder Notches
// Clears out the bottom corners to leave a solid matching interlock post
wing_notch_w = (calculated_key_w - (mount_rail_node_width - global_laser_kerf)) / 2;
wing_notch_h = mount_key_extra_leg+slot_h; // Matches your exact lower leg parameter limits
// Bottom-Left Step Shoulder
translate([-1, -1])
square([wing_notch_w + 1, wing_notch_h + 1]);
// Bottom-Right Step Shoulder
translate([calculated_key_w - wing_notch_w, -1])
square([wing_notch_w + 1, wing_notch_h + 1]);
}
// Centered handle thumb holes mapping perfectly across both configurations
if (include_key_thumb_hole) {
translate([calculated_key_w/2,calculated_key_h-mount_key_extra_top])
circle(d = thumb_d);
}
}
}
}
// Sheet labels
if (labels_include) {
color("Black") {
translate([mount_rail_length/2, mount_rail_height/2]) text("T-RAIL L1 (BASE)", size = 4, font = "Liberation Sans:style=Bold", halign="center", valign="center");
translate([mount_rail_length/2, mount_rail_height + padding + mount_rail_node_height/2]) text("T-RAIL L2 (PODS)", size = 4, font = "Liberation Sans:style=Bold", halign="center", valign = "center");
translate([mount_rail_length/2, mount_rail_height + padding + mount_rail_node_height + padding + mount_rail_height/2]) text("T-RAIL L3 (CAP)", size = 4, font = "Liberation Sans:style=Bold", halign="center", valign="center");
for(i = [0 : max(1, key_count-1)]) {
translate([mount_rail_length + padding + calculated_key_w/2, (i * (calculated_key_h + padding)) + calculated_key_h - 5])
text("LOCK KEY", size = 4, font = "Liberation Sans:style=Bold", halign="center", valign="center");
}
}
}
// ====================================================================
// 3. RECTANGULAR LAMINATION ALIGNMENT PINS (SCRAP NESTING)
// ====================================================================
// Generates clean, rectangual alignment shims scaled to thickness * 3
// to pass completely through Layers 1, 2, and 3 without poking out.
if (mount_include_alignment_pegs) {
peg_count = max(2, safe_count);
peg_w = 4.5 + global_laser_kerf; // Interference fit inside the round holes
peg_len = mat_thickness * 3; // Perfect 3-layer depth (9.0mm)
for(peg_idx = [0 : peg_count - 1]) {
// Packs the alignment pins cleanly in a horizontal row under the sliding keys
translate([mount_rail_length + padding + (peg_idx * (peg_w + padding / 2)), -peg_len -padding]) {
color("Red")
square([peg_w, peg_len]);
}
}
if (labels_include) {
color("Black")
translate([mount_rail_length + padding, -padding * 2.0])
text("ALIGN PEGS", size = 3, font = "Liberation Sans:style=Bold", halign="left", valign="center");
}
}
}
}
// ====================================================================
// BALANCED AND VERIFIED 3D ASSEMBLY SNAP MATRIX
// ====================================================================
module assembled_3d_preview() {
// 1. Back panel sits flat centered over (0,0) with 3D thickness expanding along +Z
color("Yellow", 0.9)
linear_extrude(mat_thickness)
panel_back_master_2d("ALL");
// 2. Left Wall: Placed on left margin, height centered symmetrically with back panel
color("SlateGray", 0.8)
translate([-box_inner_w/2, -side_h/2, mat_thickness])
rotate([0, -90, 0])
linear_extrude(mat_thickness)
generic_wall_2d("LEFT WALL", "ALL", false);
// 3. Right Wall: Placed on right margin, height centered symmetrically with back panel
color("SlateGray", 0.8)
translate([box_inner_w/2+mat_thickness, -side_h/2, mat_thickness])
rotate([0, -90, 0])
linear_extrude(mat_thickness)
generic_wall_2d("RIGHT WALL", "ALL", true);
// 4. Box Floor: FIXED X-AXIS OFFSET (-3mm shift to -X matches Left Wall bounds completely)
color("SaddleBrown", 0.8)
translate([-floor_w/2, -box_inner_h/2, mat_thickness])
rotate([90, 0, 0])
linear_extrude(mat_thickness)
generic_horizontal_2d("BOX FLOOR", floor_h, "ALL", true);
// 5. Top Ceiling: FIXED X-AXIS OFFSET (-3mm shift to -X maps flush matching Left Wall bounds)
color("SaddleBrown", 0.8)
translate([-floor_w/2, box_inner_h/2 + mat_thickness, mat_thickness])
rotate([90, 0, 0])
linear_extrude(mat_thickness)
generic_horizontal_2d("TOP CEILING", h_top, "ALL", false);
// ====================================================================
// 6. Clear Door
// ====================================================================
if (door_system_type != "none") {
if (door_system_type == "sliding") {
// STYLE A: Sliding door sheet positioned inside the sidewall tracking slots
color("SkyBlue", 0.3)
translate([0, (sliding_track_raster_depth - sliding_door_clearance)/2, box_inner_d])
scale([1, 1, door_thickness/mat_thickness])
linear_extrude(mat_thickness)
clear_door_panel_2d("ALL");
} else if (door_system_type == "hinged") {
// STYLE B: Swing gate panel mounted directly to the floor/ceiling holes
// FIXED 3D PIVOT: Rotation point is locked to the safe interior hole center
pivot_3d_x = -box_inner_w/2 + mat_thickness + 3.0;
//door_recess_y = box_inner_d + mat_thickness;
door_recess_y = box_inner_d + mat_thickness - mat_thickness / 2;
color("SkyBlue", 0.3)
translate([pivot_3d_x, 0, door_recess_y])
rotate([0, -0, 0]) // Controlled by your customizer angle slider
translate([-pivot_3d_x, 0, 0]) // Restores the canvas center coordinates
scale([1, 1, door_thickness/mat_thickness])
linear_extrude(mat_thickness)
clear_door_panel_2d("ALL");
}
}
// ====================================================================
// FULLY PARAMETRIC HORIZONTAL INSERTION HARDWARE MOUNT INTERLOCK
// ====================================================================
mount_z_center = 0.0 + mount_rail_vertical_offset;
// --- SYNCHRONIZED PARM MATRIX (UPDATED CONFIG VARIABLES) ---
slot_h = mount_rail_node_height;
key_top_bar_h = (mount_rail_height - mount_rail_node_height) + mount_key_extra_top;
calculated_key_h = slot_h + mount_key_extra_leg + key_top_bar_h;
calculated_key_w = mount_rail_node_width + (mount_rail_node_spacing - mount_rail_node_width) - (2 * sliding_door_clearance);
// --- DYNAMIC EDGE-STITCHING MATRIX LOGIC (FIXED RIGHT-SIDE DRIFT) ---
// Computes the number of interior spacing spans between the two absolute rail endpoints
calc_spans = floor(mount_rail_length / mount_rail_node_spacing);
safe_spans = calc_spans > 0 ? calc_spans : 1;
// LOCKED STEP: Adjusts pitch dynamically to force the last node to land exactly on the edge
active_spacing = mount_rail_half_node_endpoints ? (mount_rail_length / safe_spans) : mount_rail_node_spacing;
calc_nodes_raw = floor(mount_rail_length / active_spacing);
calc_safe_cnt = calc_nodes_raw > 0 ? calc_nodes_raw : 1;
calc_total_sp = (calc_safe_cnt - 1) * active_spacing;
safe_count = mount_rail_half_node_endpoints ? (safe_spans + 1) : calc_safe_cnt;
start_offset = mount_rail_half_node_endpoints ? 0.0 :
((mount_rail_node_justification == "CENTER") ? ((mount_rail_length - calc_total_sp) / 2) : (active_spacing / 2));
shared_hole_y = mount_rail_node_height / 2;
// --- A. THE 3-LAYER LAMINATED PROTRUDING MODULAR WALL RAIL ---
// RECALCULATED MATRIX: Layer 1 sits completely flush inside the back panel cutout at Z = 0.
// Layers 2 and 3 build forward into the clean interior of the display cabinet space.
translate([-mount_rail_length/2, mount_z_center - mount_rail_height/2, 0]) {
// Layer 1: Drywall Base Plate (Sits from Z = 0 to Z = 3mm, perfectly filling the back wood cutout)
color("DimGray")
translate([0, 0, 0])
linear_extrude(mat_thickness)
difference() {
square([mount_rail_length, mount_rail_height]);
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
x_node = (!mount_rail_half_node_endpoints) ? x_node_raw :
(i == 0) ? (mount_rail_node_width / 4) :
(i == safe_count - 1) ? (mount_rail_length - (mount_rail_node_width / 4)) : x_node_raw;
if (x_node >= 0 && x_node <= mount_rail_length) {
translate([x_node, shared_hole_y])
circle(d = 4.5);
}
}
}
// ====================================================================
// LAYER 2: SEGMENTED NECK SPACER PODS (3D PREVIEW SYNC)
// ====================================================================
// Extruded at mat_thickness, bottom-justified flush (Y translation = 0).
// Uses the exact same intersection loop to render the clipped half-nodes.
color("LightGrey")
translate([0, 0, mat_thickness])
linear_extrude(mat_thickness) {
intersection() {
square([mount_rail_length, mount_rail_node_height]);
union() {
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
x_node = (!mount_rail_half_node_endpoints) ? x_node_raw :
(i == 0) ? (mount_rail_node_width / 4) :
(i == safe_count - 1) ? (mount_rail_length - (mount_rail_node_width / 4)) : x_node_raw;
if (x_node >= 0 && x_node <= mount_rail_length) {
difference() {
translate([x_node - mount_rail_node_width/2, 0])
square([mount_rail_node_width, mount_rail_node_height]);
translate([x_node, shared_hole_y])
circle(d = 4.5);
}
}
}
}
}
}
// Layer 3: Forward Overhanging T-Cap Lip
color("DarkGray")
translate([0, 0, mat_thickness * 2])
linear_extrude(mat_thickness)
difference() {
square([mount_rail_length, mount_rail_height]);
// SCREW HOLES: Slide inward to center on the half-node material lands [INDEX]
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
x_node = (!mount_rail_half_node_endpoints) ? x_node_raw :
(i == 0) ? (mount_rail_node_width / 4) :
(i == safe_count - 1) ? (mount_rail_length - (mount_rail_node_width / 4)) : x_node_raw;
if (x_node >= 0 && x_node <= mount_rail_length) {
translate([x_node, shared_hole_y])
circle(d = 4.5);
}
}
// RESTORED SCREW HEAD RELIEFS: Locked directly to the endpoints (X=0 and X=max) [INDEX]
for(i = [0 : safe_count - 1]) {
x_node_raw = start_offset + (i * active_spacing);
if (x_node_raw >= 0 && x_node_raw <= mount_rail_length) {
translate([x_node_raw, mount_rail_height])
circle(d = thumb_d + (thumb_d*0.1));
}
}
}
}
// ====================================================================
// 2. INTERNAL VERTICAL LOCKING KEYS (The Sliding Forks - 3D PREVIEW)
// ====================================================================
for(i = [0 : safe_count - 1]) {
x_node = start_offset + (i * active_spacing);
if ((x_node - mount_rail_node_width/2 >= 0) && (x_node + mount_rail_node_width/2 <= mount_rail_length)) {
global_key_x = x_node - mount_rail_length/2;
// Positions the key's throat roof flush with the top of Layer 2
color("LimeGreen", 0.5)
translate([global_key_x, mount_z_center - mount_rail_height/2 + mount_rail_node_height - slot_h, mat_thickness])
linear_extrude(mat_thickness)
difference() {
translate([-calculated_key_w/2, -mount_key_extra_leg])
square([calculated_key_w, calculated_key_h]);
slot_top_w = mount_rail_node_width;
slot_bot_w = mount_rail_node_width + 1.2;
polygon(points=[
[-slot_bot_w/2, -mount_key_extra_leg - 1],
[-slot_top_w/2, slot_h],
[slot_top_w/2, slot_h],
[slot_bot_w/2, -mount_key_extra_leg - 1]
]);
if (include_key_thumb_hole) {
translate([0,mount_rail_height])
circle(d = thumb_d);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment