Created
June 12, 2026 14:29
-
-
Save haliphax/c4f962f049acadb3d09b9038665d4d24 to your computer and use it in GitHub Desktop.
Grid generator script for producing unionized grid meshes from an STL file and gap pad meshes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Generates a grid of body meshes with pad meshes between them. | |
| // "Fence-post" pattern: N bodies get N-1 pads between them. | |
| // | |
| // STL files must be in the same directory as this script, | |
| // or provide absolute paths. | |
| // | |
| // Pad STLs should have their geometry positioned in object-local | |
| // coordinates so that when placed at the same grid points as the | |
| // bodies, they naturally align into the gaps: | |
| // - h_pad.stl: offset to bridge the horizontal gap | |
| // - v_pad.stl: offset to bridge the vertical gap | |
| // - gap_pad.stl: offset to fit into the interior corner where | |
| // 4 bodies meet (bottom-right corner of the grid point body) | |
| /* [Grid Parameters] */ | |
| // Number of bodies horizontally (X direction) | |
| body_count_x = 3; | |
| // Number of bodies vertically (Y direction) | |
| body_count_y = 2; | |
| // Horizontal spacing between body placement points (mm) | |
| horizontal_offset = 42; | |
| // Vertical spacing between body placement points (mm) | |
| vertical_offset = 42; | |
| /* [STL File Paths] */ | |
| // Body mesh STL file | |
| body_stl = "body.stl"; | |
| // Horizontal pad mesh STL file | |
| h_pad_stl = "h_pad.stl"; | |
| // Vertical pad mesh STL file | |
| v_pad_stl = "v_pad.stl"; | |
| // Gap pad mesh STL file — fills interior corners where 4 bodies meet | |
| gap_pad_stl = "gap_pad.stl"; | |
| /* [Hidden] */ | |
| module at_grid(x, y) { | |
| translate([x * horizontal_offset, y * vertical_offset, 0]) | |
| children(); | |
| } | |
| // ======================== | |
| // MAIN RENDERING | |
| // ======================== | |
| // Bodies: full grid | |
| for (x = [0 : body_count_x - 1]) { | |
| for (y = [0 : body_count_y - 1]) { | |
| at_grid(x, y) | |
| import(body_stl); | |
| } | |
| } | |
| // Horizontal pads: (body_count_x - 1) x body_count_y | |
| if (body_count_x > 1) { | |
| for (x = [0 : body_count_x - 2]) { | |
| for (y = [0 : body_count_y - 1]) { | |
| at_grid(x, y) | |
| import(h_pad_stl); | |
| } | |
| } | |
| } | |
| // Vertical pads: body_count_x x (body_count_y - 1) | |
| if (body_count_y > 1) { | |
| for (x = [0 : body_count_x - 1]) { | |
| for (y = [0 : body_count_y - 2]) { | |
| at_grid(x, y) | |
| import(v_pad_stl); | |
| } | |
| } | |
| } | |
| // Gap pads: (body_count_x - 1) x (body_count_y - 1) | |
| // Fence-post in both axes — fills interior corners where 4 bodies meet. | |
| // Placed at (1..cx-1, 0..cy-2) since the gap pad's local geometry | |
| // extends in -X and +Y from its placement point. | |
| if (body_count_x > 1 && body_count_y > 1) { | |
| for (x = [1 : body_count_x - 1]) { | |
| for (y = [0 : body_count_y - 2]) { | |
| at_grid(x, y) | |
| import(gap_pad_stl); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment