Skip to content

Instantly share code, notes, and snippets.

@deckar01
Created July 24, 2018 22:27
Show Gist options
  • Save deckar01/ef11def51de7e71d9f288c6e5819fdb7 to your computer and use it in GitHub Desktop.
Save deckar01/ef11def51de7e71d9f288c6e5819fdb7 to your computer and use it in GitHub Desktop.
OpenSCAD Bricks Benchmark
INCHES = 25.4;
brick_depth = (3 + 5/8) * INCHES;
brick_height = (2 + 1/4) * INCHES;
brick_length = (7 + 5/8) * INCHES;
mortar_gap = (3/8) * INCHES;
module Brick() {
cube([brick_length, brick_depth, brick_height]);
}
module HalfBrick() {
cube([(brick_length - mortar_gap)/2, brick_depth, brick_height]);
}
module Row(length) {
for(x = [0:length - 1]) {
translate([(brick_length + mortar_gap)*x, 0, 0])
Brick();
}
}
module Wall(length, height, alternate=0) {
for(z = [0:height - 1]) {
offset = (z + alternate) % 2;
translate([offset*(brick_depth + mortar_gap), 0, (brick_height + mortar_gap)*z])
Row(length);
}
}
module Floor(length, width) {
Walls(length, width, 1);
if(length > 1 && width > 1) {
translate([brick_depth + mortar_gap, brick_depth + mortar_gap, 0])
Floor(length - 1, width - 1);
}
if(length == 1 && width > 1) {
translate([2*(brick_depth) + mortar_gap, brick_depth + mortar_gap, 0])
rotate([0, 0, 90])
Row(width - 1);
}
if(width == 1 && length > 1) {
translate([2*(brick_depth + mortar_gap), brick_depth + mortar_gap, 0])
Row(length - 1);
}
translate([brick_depth + mortar_gap, brick_depth + mortar_gap, 0])
HalfBrick();
}
module Walls(length, width, height) {
Wall(length, height);
translate([brick_depth, 0, 0])
rotate([0, 0, 90])
Wall(width, height, 1);
translate([0, (width)*(brick_length + mortar_gap), 0])
Wall(length, height, 1);
translate([(length + 0.5)*(brick_length + mortar_gap) - mortar_gap, 0, 0])
rotate([0, 0, 90])
Wall(width, height);
}
width = 10;
length = 10;
height = 10;
color("FireBrick")
Walls(width, length, height);
color("Gold")
translate([brick_depth + mortar_gap, brick_depth + mortar_gap, 0])
Floor(width - 1, length - 1);
@ochafik
Copy link

ochafik commented Jan 29, 2021

FYI, linked to this cool benchmark in a PR I sent to OpenSCAD (openscad/openscad#3636) to speed up the rendering of unions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment