Skip to content

Commit e88a398

Browse files
committed
lots of stuff
* added new hex key shape * moved corner and side sculpting functions into special variables * fixed negative inset stems sticking out the top * added corner smoothing functionality to 3d surface dishes
1 parent ec44ef7 commit e88a398

File tree

19 files changed

+495
-118
lines changed

19 files changed

+495
-118
lines changed

TODO.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
TODO:
2-
* Make flat stem support default
2+
* implement key_shape_at_progress which allows you to query for the exact 2d outline of the keycap at a given height
3+
* this makes certain functions easier - building the envelope for instance
4+
* requires breaking out shape_slice, and creating a polygon of the skin_shape_slice slices
5+
* dishes add / remove height from keycaps, particularly spherical dishes
6+
* a bandaid solution would be to allow you to modify where the keytop is along the progression of the keycap
7+
* you can't just set a new total_depth because of how width_difference and height_difference work
8+
* the true solution would be to rewrite how the dishes work to make them very graduated at the edges
39
* implement regular polygon for skin extrusions
410
* switch to skin-shaped extrusions by default
511
* kailh choc has a non-square key unit; should I get that working for layouts etc?

customizer.scad

Lines changed: 306 additions & 74 deletions
Large diffs are not rendered by default.

keys.scad

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,38 @@
88
include <./includes.scad>
99

1010

11+
// $rounded_key = true;
1112
// example key
12-
dcs_row(5) legend("⇪", size=9) key();
13+
// typewriter_row(5) legend("⇪", size=9) resin() key();
1314

14-
// example row
15-
/* for (x = [0:1:4]) {
16-
translate_u(0,-x) dcs_row(x) key();
17-
} */
15+
// // example row
16+
// for(y = [0:1:3]) {
17+
// for (x = [0:1:4]) {
18+
// translate_u(x + y % 2 * 0.5,y) hex_row(x) key();
19+
// }
20+
// }
21+
22+
// $double_sculpted = true;
23+
// row_length = len(preonic_mit_layout[0]);
24+
// simple_layout(preonic_mit_layout) {
25+
// $keycap_rotation = 90;
26+
// // $stem_type = "choc";
27+
// adjusted_column = [-1, -1/2, 0, 1/2, 0, -1/2, -1/2, 0, 1/2, 0, -1/2, -1];
28+
// column_value = double_sculpted_column($column, row_length, "2hands");
29+
// translate_u(0, adjusted_column[$column]) hex_row($row, column_value) {
30+
// key();
31+
// }
32+
// }
33+
34+
// $hull_shape_type = "skin";
35+
dsa_row(1) key();
36+
translate_u(1) dsa_row(1) {
37+
union() {
38+
// $total_depth = 11;
39+
$inverted_dish = true;
40+
key();
41+
}
42+
}
1843

1944
// example layout
2045
/* preonic_default("dcs") key(); */

src/dishes/3d_surface.scad

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module 3d_surface_dish(width, height, depth, inverted) {
66
// it doesn't have to be dead reckoning for anything but sculpted sides
77
// we know the angle of the sides from the width difference, height difference,
88
// skew and tilt of the top. it's a pain to calculate though
9-
scale_factor = 1.11;
9+
scale_factor = 1.05;
1010
// the edges on this behave differently than with the previous dish implementations
1111
scale([width*scale_factor/$3d_surface_size/2,height*scale_factor/$3d_surface_size/2,depth])
1212
rotate([inverted ? 0:180,0,180])

src/dishes/spherical.scad

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module spherical_dish(width, height, depth, inverted){
2+
// these variables take into account corner_radius and corner_sculpting, resulting in a more correct dish
3+
// they don't fix the core issue though (dishes adding / subtracting height on the edges of the keycap), so I've disabled them
4+
// new_width = $key_shape_type == "sculpted_square" ? width - distance_between_circumscribed_and_inscribed($corner_radius + $corner_sculpting(1)) : width;
5+
// new_height = $key_shape_type == "sculpted_square" ? height - distance_between_circumscribed_and_inscribed($corner_radius + $corner_sculpting(1)) : height;
26

37
//same thing as the cylindrical dish here, but we need the corners to just touch - so we have to find the hypotenuse of the top
48
chord = pow((pow(width,2) + pow(height, 2)),0.5); //getting diagonal of the top

src/functions.scad

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include <constants.scad>
44
// functions need to be explicitly included, unlike special variables, which
55
// just need to have been set before they are used. hence this file
66

7-
function stem_height() = $total_depth - $dish_depth - $stem_inset;
7+
function stem_height() = $total_depth - ($dish_depth * ($inverted_dish ? -1 : 1)) - $stem_inset;
88

99
// cherry stem dimensions
1010
function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2];
@@ -23,6 +23,10 @@ function cherry_cross(slop, extra_vertical = 0) = [
2323
[1.15 + slop / 3, 4.23 + extra_vertical + slop / 3 + SMALLEST_POSSIBLE],
2424
];
2525

26+
// TODO add side_sculpting
27+
function key_width_at_progress(progress = 0) = $bottom_key_width + ($unit * ($key_length - 1)) - $width_difference;
28+
function key_height_at_progress(progress = 0) = $bottom_key_height + ($unit * ($key_length - 1)) - $height_difference + $side_sculpting(progress);
29+
2630
// actual mm key width and height
2731
function total_key_width(delta = 0) = $bottom_key_width + $unit * ($key_length - 1) - delta;
2832
function total_key_height(delta = 0) = $bottom_key_height + $unit * ($key_height - 1) - delta;
@@ -47,3 +51,7 @@ function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_in
4751
function add_rounding(p, radius)=[for(i=[0:len(p)-1])[p[i].x,p[i].y, radius]];
4852
// computes millimeter length from unit length
4953
function unit_length(length) = $unit * (length - 1) + 18.16;
54+
55+
// if you have a radius of an inscribed circle, this function gives you the extra length for the radius of the circumscribed circle
56+
// and vice versa. used to find the edge of a rounded_square
57+
function distance_between_circumscribed_and_inscribed(radius) = (pow(2, 0.5) - 1) * radius;

src/key.scad

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use <libraries/scad-utils/lists.scad>
1717
use <libraries/scad-utils/shapes.scad>
1818
use <libraries/skin.scad>
1919

20-
// key shape including dish. used as the ouside and inside shape in hollow_key(). allows for itself to be shrunk in depth and width / height
20+
// key shape including dish. used as the outside and inside shape in hollow_key(). allows for itself to be shrunk in depth and width / height
2121
module shape(thickness_difference, depth_difference=0){
2222
dished(depth_difference, $inverted_dish) {
2323
color($primary_color) shape_hull(thickness_difference, depth_difference, $inverted_dish ? 200 : 0);
@@ -46,12 +46,13 @@ module minkowski_object() {
4646
}
4747
}
4848

49-
module envelope(depth_difference=0) {
50-
s = 1.5;
49+
module envelope(depth_difference=0, extra_floor_depth=0) {
50+
size = 1.5;
51+
5152
hull(){
52-
cube([total_key_width() * s, total_key_height() * s, 0.01], center = true);
53+
translate([0,0,extra_floor_depth]) cube([key_width_at_progress(extra_floor_depth / $total_depth) * size, key_height_at_progress(extra_floor_depth / $total_depth) * size, 0.01], center = true);
5354
top_placement(SMALLEST_POSSIBLE + depth_difference){
54-
cube([top_total_key_width() * s, top_total_key_height() * s, 0.01], center = true);
55+
cube([top_total_key_width() * size, top_total_key_height() * size, 0.01], center = true);
5556
}
5657
}
5758
}
@@ -64,12 +65,12 @@ module dished(depth_difference = 0, inverted = false) {
6465
children();
6566
difference(){
6667
union() {
67-
// envelope is needed to "fill in" the rest of the keycap
68-
envelope(depth_difference);
68+
// envelope is needed to "fill in" the rest of the keycap. intersections with small objects are much faster than differences with large objects
69+
envelope(depth_difference, $stem_inset);
6970
if (inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted);
7071
}
7172
if (!inverted) top_placement(depth_difference) color($secondary_color) _dish(inverted);
72-
/* %top_placement(depth_difference) _dish(); */
73+
// %top_placement(depth_difference) _dish();
7374
}
7475
}
7576
}
@@ -79,6 +80,7 @@ module dished(depth_difference = 0, inverted = false) {
7980
module _dish(inverted=$inverted_dish) {
8081
translate([$dish_offset_x,0,0]) color($secondary_color)
8182
dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, inverted);
83+
// %dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, inverted);
8284
}
8385

8486
// puts its children at each keystem position provided
@@ -239,7 +241,7 @@ module key(inset=false) {
239241
};
240242

241243
if ($inner_shape_type != "disable") {
242-
translate([0,0,-SMALLEST_POSSIBLE]) {
244+
translate([0,0,-SMALLEST_POSSIBLE]) { // avoids moire
243245
inner_total_shape();
244246
}
245247
}
@@ -249,10 +251,12 @@ module key(inset=false) {
249251
};
250252
}
251253

252-
// if $stem_inset is less than zero, we add the
254+
// semi-hack to make sure negative inset stems don't poke through the top of the keycap
253255
if ($stem_inset < 0) {
254-
stems_and_stabilizers();
255-
}
256+
dished(0, $inverted_dish) {
257+
stems_and_stabilizers();
258+
}
259+
}
256260
}
257261

258262
// actual full key with space carved out and keystem/stabilizer connectors

src/key_profiles.scad

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include <key_profiles/cherry.scad>
1515
include <key_profiles/dss.scad>
1616
include <key_profiles/asa.scad>
1717
include <key_profiles/typewriter.scad>
18+
include <key_profiles/hex.scad>
1819

1920
// man, wouldn't it be so cool if functions were first order
2021
module key_profile(key_profile_type, row, column=0) {
@@ -38,6 +39,8 @@ module key_profile(key_profile_type, row, column=0) {
3839
grid_row(row, column) children();
3940
} else if (key_profile_type == "typewriter") {
4041
typewriter_row(row, column) children();
42+
} else if (key_profile_type == "hex") { // reddit.com/r/MechanicalKeyboards/comments/kza7ji
43+
hex_row(row, column) children();
4144
} else if (key_profile_type == "hexagon") {
4245
hexagonal_row(row, column) children();
4346
} else if (key_profile_type == "octagon") {

src/key_profiles/asa.scad

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ module asa_row(row=3, column = 0) {
1313
$top_skew = 1.75;
1414
$stem_inset = 1.2;
1515
$height_slices = 10;
16+
1617
$corner_radius = 1;
18+
$more_side_sculpting_factor = 0.4;
19+
20+
$side_sculpting = function(progress) (1 - progress) * 4.5;
21+
$corner_sculpting = function(progress) pow(progress, 2);
1722

1823
// this is _incredibly_ intensive
1924
//$rounded_key = true;

src/key_profiles/dsa.scad

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ module dsa_row(row=3, column = 0) {
1111
$dish_skew_x = 0;
1212
$dish_skew_y = 0;
1313
$height_slices = 10;
14-
$enable_side_sculpting = true;
14+
15+
$dish_type = "3d surface";
16+
$surface_function = spherical_surface;
17+
18+
$side_sculpting = function(progress) (1 - progress) * 4.5;
19+
$corner_sculpting = function(progress) pow(progress, 2);
20+
1521
$corner_radius = 1;
22+
$more_side_sculpting_factor = 0.4;
1623

1724
$top_tilt_y = side_tilt(column);
1825
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;

0 commit comments

Comments
 (0)