def upper_plate_2(lines, padding=5): w, h = size(lines) w *= SPACING h *= SPACING w += padding * 2 h += padding * 2 doc = Difference() doc.append([ Translate([0, 0, 0]).append([ Hull().append( Minkowski().append([ upper_cutout(lines, depth=1.5, break_at=210, break_at_one_before=True), Cube([padding * 2, padding * 2, 0.01], center=True) ]) ), # Hull().append( Minkowski().append([ upper_cutout(lines, depth=1.5, break_at=210), Cube([padding * 2, padding * 2, 0.01], center=True) ]) # ), ]), upper_cutout(lines, depth=1.6, break_at=220), ]) return doc
def upper_cutout(lines, depth=1, break_at=None, break_at_one_before=False, use_width=True): doc = Translate([0, 0, 0]) y = 0 for x, y, width, height in generate_keys(lines, generate_2=True, break_at=break_at, break_at_one_before=break_at_one_before, use_width=not use_width): k = Cube([SPACING * (width if use_width else 1), SPACING * height, depth], center=True) doc.append(k.translate([SPACING * x, SPACING * y, 0])) return doc
def key_plate_outer_rhs(lines, padding=5): return Difference().append([ Hull().append( Minkowski().append([ upper_cutout(lines, depth=4.4), Cube([padding * 2, padding * 2, 0.2]), ]) ), Minkowski().append([ key_plate_outer_lhs(lines, padding), Cube(0.25, center=True) ]) ])
def key_plate_box(lines, depth=1): doc = Translate([0, 0, 0]) for x, y, width, height in generate_keys(lines): doc.append( Cube([SPACING * width, SPACING * height, depth], center=True) .translate([SPACING * x, SPACING * y, 0]) ) return doc
def key_plate_outer_lhs(lines, padding=5): return Union().append([ Hull().append( Minkowski().append([ upper_cutout(lines, depth=4.4, break_at=200, break_at_one_before=True, use_width=True), Cube([padding * 2, padding * 2, 0.2]), ]) ), Hull().append( Minkowski().append([ upper_cutout(lines, depth=4.4, break_at=250, break_at_one_before=True, use_width=False), Cube([padding * 2, padding * 2, 0.2]), ]) ), Minkowski().append([ upper_cutout(lines, depth=4.4, break_at=250, break_at_one_before=False, use_width=True), Cube([padding, padding, 0.2]), ]) ])
def plane_key(width, height, depth): k = Union() cube = Cube([SIZE, SIZE, depth], center=True) k.append(cube) if width == 2: k.append(stabilizer(23.12, depth)) elif height == 2: k.append(stabilizer(23.12, depth).rotate([0, 0, 90])) elif width == 6.25: k.append(stabilizer(100, depth)) return k
def upper_plate(lines, padding=5): w, h = size(lines) w *= SPACING h *= SPACING w += padding * 2 h += padding * 2 doc = Difference() doc.append( Cube([w, h, 1.5], center=True) .translate([-SPACING / 2, -SPACING / 2, 0]) .translate([-padding, -padding, 0]) .translate([w / 2, h / 2, 0]) ) doc.append(upper_cutout(lines, depth=1.6)) return doc
def stabilizer(width, depth): stab = Union() stab.append(Cube([width, 4.6, depth], center=True)) lhs = Translate([-width / 2, 0.62, 0]) lhs.append([ Cube([6.75, 12.3, depth], center=True).translate([0, 0, 0]), Cube([3.3, 1.2, depth], center=True).translate([0, 6.75, 0]), Cube([0.82 + 0.01, 2.8, depth], center=True).translate([-3.79, -1.52, 0]), ]) stab.append(lhs) rhs = Translate([width / 2, 0.62, 0]) rhs.append([ Cube([6.75, 12.3, depth], center=True).translate([0, 0, 0]), Cube([3.3, 1.2, depth], center=True).translate([0, 6.75, 0]), Cube([0.82 + 0.01, 2.8, depth], center=True).translate([3.79, -1.52, 0]), ]) stab.append(rhs) return stab
def main(layout_json): with open(layout_json) as fh: layout = json.load(fh) data = layout[0] lines = layout[1:] print(f"Generating keyboard {data}") print(f"Size {size(lines)}") doc = Translate([0, 0, 0]) doc.append(key_plate_lhs(lines)) doc.append(key_plate_rhs(lines, 5).translate([35, 0, 0])) doc.write("key_plate.scad") # convert("key_plate") doc2 = Intersection() doc2.append(doc) doc2.append(Translate([200, -20, -10]).append(Cube([100, 180, 50]))) doc2.write("key_plate_test.scad") doc = Translate([0, 0, 0]) doc.append(upper_plate_2(lines)) doc.write("upper_plate.scad")