diff --git a/customizer.scad b/customizer.scad index fbb484d..a0313f1 100644 --- a/customizer.scad +++ b/customizer.scad @@ -199,11 +199,6 @@ $tertiary_color = [1, .6941, .2]; $quaternary_color = [.4078, .3569, .749]; $warning_color = [1,0,0, 0.15]; -// 3d surface variables - -$3d_surface_size = 0.5; -$3d_surface_step = .05; - // key width functions module u(u=1) { @@ -2165,76 +2160,6 @@ module geodesic_sphere(r=-1, d=-1) { scale(rad) polyhedron(points=subdiv_icos[0], faces=subdiv_icos[1]); } -module 3d_surface(size=$3d_surface_size, step=$3d_surface_step){ - bottom = 0; - function p(x, y) = [ x, y, surface_function(x, y) ]; - function p0(x, y) = [ x, y, bottom ]; - function rev(b, v) = b ? v : [ v[3], v[2], v[1], v[0] ]; - function face(x, y) = [ p(x, y + step), p(x + step, y + step), p(x + step, y), p(x + step, y), p(x, y), p(x, y + step) ]; - function fan(a, i) = - a == 0 ? [ [ 0, 0, bottom ], [ i, -size, bottom ], [ i + step, -size, bottom ] ] - : a == 1 ? [ [ 0, 0, bottom ], [ i + step, size, bottom ], [ i, size, bottom ] ] - : a == 2 ? [ [ 0, 0, bottom ], [ -size, i + step, bottom ], [ -size, i, bottom ] ] - : [ [ 0, 0, bottom ], [ size, i, bottom ], [ size, i + step, bottom ] ]; - function sidex(x, y) = [ p0(x, y), p(x, y), p(x + step, y), p0(x + step, y) ]; - function sidey(x, y) = [ p0(x, y), p(x, y), p(x, y + step), p0(x, y + step) ]; - - points = flatten(concat( - // top surface - [ for (x = [ -size : step : size - step ], y = [ -size : step : size - step ]) face(x, y) ], - // bottom surface as triangle fan - [ for (a = [ 0 : 3 ], i = [ -size : step : size - step ]) fan(a, i) ] - // sides - /* [ for (x = [ -size : step : size - step ], y = [ -size, size ]) rev(y < 0, sidex(x, y)) ], */ - /* [ for (y = [ -size : step : size - step ], x = [ -size, size ]) rev(x > 0, sidey(x, y)) ] */ - )); - - tcount = 2 * pow(2 * size / step, 2) + 8 * size / step; - scount = 8 * size / step; - - tfaces = [ for (a = [ 0 : 3 : 3 * (tcount - 1) ] ) [ a, a + 1, a + 2 ] ]; - sfaces = [ for (a = [ 3 * tcount : 4 : 3 * tcount + 4 * scount ] ) [ a, a + 1, a + 2, a + 3 ] ]; - faces = concat(tfaces, sfaces); - - polyhedron(points, faces, convexity = 8); -} - -module polar_3d_surface(size=$3d_surface_size, step=$3d_surface_step){ - function to_polar(q) = q * (90 / size); - - function p(x, y) = [ sin(to_polar(x)) * size, sin(to_polar(y)) * size, surface_function(sin(to_polar(x)) * size, sin(to_polar(y)) * size) ]; - function p0(x, y) = [ x, y, 0 ]; - function rev(b, v) = b ? v : [ v[3], v[2], v[1], v[0] ]; - function face(x, y) = [ p(x, y + step), p(x + step, y + step), p(x + step, y), p(x + step, y), p(x, y), p(x, y + step) ]; - function fan(a, i) = - a == 0 ? [ [ 0, 0, 0 ], [ sin(to_polar(i))*size, -size, 0 ], [ sin(to_polar((i + step)))*size, -size, 0 ] ] - : a == 1 ? [ [ 0, 0, 0 ], [ sin(to_polar(i + step))*size, size, 0 ], [ sin(to_polar(i))*size, size, 0 ] ] - : a == 2 ? [ [ 0, 0, 0 ], [ -size, sin(to_polar(i + step))*size, 0 ], [ -size, sin(to_polar(i))*size, 0 ] ] - : [ [ 0, 0, 0 ], [ size, sin(to_polar(i))*size, 0 ], [ size, sin(to_polar(i + step))*size, 0 ] ]; - function sidex(x, y) = [ p0(x, y), p(x, y), p(x + step, y), p0(x + step, y) ]; - function sidey(x, y) = [ p0(x, y), p(x, y), p(x, y + step), p0(x, y + step) ]; - - points = flatten(concat( - // top surface - [ for (x = [ -size : step : size - step ], y = [ -size : step : size - step ]) face(x, y) ], - // bottom surface as triangle fan - [ for (a = [ 0 : 3 ], i = [ -size : step : size - step ]) fan(a, i) ] - // sides - /* [ for (x = [ -size : step : size - step ], y = [ -size, size ]) rev(y < 0, sidex(x, y)) ], */ - /* [ for (y = [ -size : step : size - step ], x = [ -size, size ]) rev(x > 0, sidey(x, y)) ] */ - )); - - tcount = 2 * pow(2 * size / step, 2) + 8 * size / step; - scount = 8 * size / step; - - tfaces = [ for (a = [ 0 : 3 : 3 * (tcount - 1) ] ) [ a, a + 1, a + 2 ] ]; - sfaces = [ for (a = [ 3 * tcount : 4 : 3 * tcount + 4 * scount ] ) [ a, a + 1, a + 2, a + 3 ] ]; - faces = concat(tfaces, sfaces); - - polyhedron(points, faces, convexity = 8); -} - -function surface_function(x,y) = $dish_depth * (sin(acos(x/$3d_surface_size))) * sin(acos(y/$3d_surface_size)); module cylindrical_dish(width, height, depth, inverted){ // .5 has problems starting around 3u @@ -2321,9 +2246,6 @@ module spherical_dish(width, height, depth, inverted){ module flat_dish(width, height, depth, inverted){ cube([width + 100,height + 100, depth], center=true); } -module 3d_surface_dish(width, height, depth, inverted) { - scale([width*2,height*2,depth]) rotate([180,0,0]) polar_3d_surface(); -} //geodesic looks much better, but runs very slow for anything above a 2u geodesic=false; @@ -2343,8 +2265,6 @@ module dish(width, height, depth, inverted) { old_spherical_dish(width, height, depth, inverted); } else if ($dish_type == "flat") { flat_dish(width, height, depth, inverted); - } else if ($dish_type == "3d_surface") { - 3d_surface_dish(width, height, depth, inverted); } else if ($dish_type == "disable") { // else no dish } else { @@ -2475,6 +2395,8 @@ module supports(type, stem_type, loft, height) { echo("Warning: unsupported $support_type"); } } +// features are any premade self-contained objects that go on top or inside + module keybump(depth = 0, edge_inset=0.4) { radius = 0.5; translate([0, -top_total_key_height()/2 + edge_inset, depth]){ @@ -2482,6 +2404,56 @@ module keybump(depth = 0, edge_inset=0.4) { translate([0,0,-radius]) cube([$font_size, radius*2, radius*2], true); } } +// a fake cherry keyswitch, abstracted out to maybe replace with a better one later +module cherry_keyswitch() { + union() { + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); + } + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); + } + } +} + +//approximate (fully depressed) cherry key to check clearances +module clearance_check() { + if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ + color($warning_color){ + translate([0,0,3.6 + $stem_inset - 5]) { + cherry_keyswitch(); + } + } + } +} +module keytext(text, position, font_size, depth) { + woffset = (top_total_key_width()/3.5) * position[0]; + hoffset = (top_total_key_height()/3.5) * -position[1]; + translate([woffset, hoffset, -depth]){ + color($tertiary_color) linear_extrude(height=$dish_depth){ + text(text=text, font=$font, size=font_size, halign="center", valign="center"); + } + } +} + +module legends(depth=0) { + if (len($front_legends) > 0) { + front_of_key() { + for (i=[0:len($front_legends)-1]) { + rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); + } + } + } + if (len($legends) > 0) { + top_of_key() { + for (i=[0:len($legends)-1]) { + keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); + } + } + } +} // from https://www.thingiverse.com/thing:1484333 // public domain license @@ -3442,22 +3414,22 @@ module shape(thickness_difference, depth_difference=0){ // shape of the key but with soft, rounded edges. no longer includes dish // randomly doesnt work sometimes // the dish doesn't _quite_ reach as far as it should -/* module rounded_shape() { +module rounded_shape() { dished(-$minkowski_radius, $inverted_dish) { color($primary_color) minkowski(){ // half minkowski in the z direction color($primary_color) shape_hull($minkowski_radius * 2, $minkowski_radius/2, $inverted_dish ? 2 : 0); - // cube($minkowski_radius); + /* cube($minkowski_radius); */ sphere(r=$minkowski_radius, $fn=48); } } - // %envelope(); -} */ + /* %envelope(); */ +} // this function is more correct, but takes _forever_ // the main difference is minkowski happens after dishing, meaning the dish is // also minkowski'd -module rounded_shape() { +/* module rounded_shape() { color($primary_color) minkowski(){ // half minkowski in the z direction shape($minkowski_radius * 2, $minkowski_radius/2); @@ -3468,7 +3440,7 @@ module rounded_shape() { } } } -} +} */ @@ -3682,16 +3654,6 @@ module top_of_key(){ } } -module keytext(text, position, font_size, depth) { - woffset = (top_total_key_width()/3.5) * position[0]; - hoffset = (top_total_key_height()/3.5) * -position[1]; - translate([woffset, hoffset, -depth]){ - color($tertiary_color) linear_extrude(height=$dish_depth){ - text(text=text, font=$font, size=font_size, halign="center", valign="center"); - } - } -} - module keystem_positions(positions) { for (connector_pos = positions) { translate(connector_pos) { @@ -3717,53 +3679,6 @@ module stems_for(positions, stem_type) { } } -// a fake cherry keyswitch, abstracted out to maybe replace with a better one later -module cherry_keyswitch() { - union() { - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); - } - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); - } - } -} - -//approximate (fully depressed) cherry key to check clearances -module clearance_check() { - if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ - color($warning_color){ - translate([0,0,3.6 + $stem_inset - 5]) { - cherry_keyswitch(); - } - } - } -} - -module legends(depth=0) { - if (len($front_legends) > 0) { - front_placement() { - if (len($front_legends) > 0) { - for (i=[0:len($front_legends)-1]) { - rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); - } - } - } - } - if (len($legends) > 0) { - top_of_key() { - // outset legend - if (len($legends) > 0) { - for (i=[0:len($legends)-1]) { - keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); - } - } - } - } -} - // legends / artisan support module artisan(depth) { top_of_key() { @@ -4026,11 +3941,6 @@ $secondary_color = [.4412, .7, .3784]; $tertiary_color = [1, .6941, .2]; $quaternary_color = [.4078, .3569, .749]; $warning_color = [1,0,0, 0.15]; - -// 3d surface variables - -$3d_surface_size = 0.5; -$3d_surface_step = .05; key(); } diff --git a/src/features.scad b/src/features.scad new file mode 100644 index 0000000..b0ae94a --- /dev/null +++ b/src/features.scad @@ -0,0 +1,5 @@ +// features are any premade self-contained objects that go on top or inside + +include +include +include diff --git a/src/features/clearance_check.scad b/src/features/clearance_check.scad new file mode 100644 index 0000000..96c4d70 --- /dev/null +++ b/src/features/clearance_check.scad @@ -0,0 +1,24 @@ +// a fake cherry keyswitch, abstracted out to maybe replace with a better one later +module cherry_keyswitch() { + union() { + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); + } + hull() { + cube([15.6, 15.6, 0.01], center=true); + translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); + } + } +} + +//approximate (fully depressed) cherry key to check clearances +module clearance_check() { + if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ + color($warning_color){ + translate([0,0,3.6 + $stem_inset - 5]) { + cherry_keyswitch(); + } + } + } +} diff --git a/src/features/legends.scad b/src/features/legends.scad new file mode 100644 index 0000000..e657218 --- /dev/null +++ b/src/features/legends.scad @@ -0,0 +1,26 @@ +module keytext(text, position, font_size, depth) { + woffset = (top_total_key_width()/3.5) * position[0]; + hoffset = (top_total_key_height()/3.5) * -position[1]; + translate([woffset, hoffset, -depth]){ + color($tertiary_color) linear_extrude(height=$dish_depth){ + text(text=text, font=$font, size=font_size, halign="center", valign="center"); + } + } +} + +module legends(depth=0) { + if (len($front_legends) > 0) { + front_of_key() { + for (i=[0:len($front_legends)-1]) { + rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); + } + } + } + if (len($legends) > 0) { + top_of_key() { + for (i=[0:len($legends)-1]) { + keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); + } + } + } +} diff --git a/src/key.scad b/src/key.scad index d1efedd..16373f4 100644 --- a/src/key.scad +++ b/src/key.scad @@ -5,7 +5,7 @@ include include include include -include +include include @@ -271,16 +271,6 @@ module top_of_key(){ } } -module keytext(text, position, font_size, depth) { - woffset = (top_total_key_width()/3.5) * position[0]; - hoffset = (top_total_key_height()/3.5) * -position[1]; - translate([woffset, hoffset, -depth]){ - color($tertiary_color) linear_extrude(height=$dish_depth){ - text(text=text, font=$font, size=font_size, halign="center", valign="center"); - } - } -} - module keystem_positions(positions) { for (connector_pos = positions) { translate(connector_pos) { @@ -306,53 +296,6 @@ module stems_for(positions, stem_type) { } } -// a fake cherry keyswitch, abstracted out to maybe replace with a better one later -module cherry_keyswitch() { - union() { - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,1,5 - 0.01]) cube([10.5,9.5, 0.01], center=true); - } - hull() { - cube([15.6, 15.6, 0.01], center=true); - translate([0,0,-5.5]) cube([13.5,13.5,0.01], center=true); - } - } -} - -//approximate (fully depressed) cherry key to check clearances -module clearance_check() { - if($stem_type == "cherry" || $stem_type == "cherry_rounded"){ - color($warning_color){ - translate([0,0,3.6 + $stem_inset - 5]) { - cherry_keyswitch(); - } - } - } -} - -module legends(depth=0) { - if (len($front_legends) > 0) { - front_placement() { - if (len($front_legends) > 0) { - for (i=[0:len($front_legends)-1]) { - rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth); - } - } - } - } - if (len($legends) > 0) { - top_of_key() { - // outset legend - if (len($legends) > 0) { - for (i=[0:len($legends)-1]) { - keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); - } - } - } - } -} - // legends / artisan support module artisan(depth) { top_of_key() {