forked from rsheldiii/KeyV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customizer.scad
3948 lines (3288 loc) · 137 KB
/
customizer.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// entry point for customizer script. This probably isn't useful to most people,
// as it's just a wrapper that helps generate customizer.scad for thingiverse.
/* [Basic-Settings] */
// what preset profile do you wish to use? disable if you are going to set paramters below
key_profile = "dcs"; // [dcs, oem, dsa, sa, g20, disable]
// what key profile row is this keycap on? 0 for disable
row = 1; // [5,1,2,3,4,0]
// What does the top of your key say?
legend = "";
$using_customizer = true;
/* [Basic-Settings] */
// Length in units of key. A regular key is 1 unit; spacebar is usually 6.25
$key_length = 1.0; // Range not working in thingiverse customizer atm [1:0.25:16]
// What type of stem you want. Most people want Cherry.
$stem_type = "cherry"; // [cherry, alps, rounded_cherry, box_cherry, filled, disable]
// The stem is the hardest part to print, so this variable controls how much 'slop' there is in the stem
// if your keycaps stick in the switch raise this value
$stem_slop = 0.35; // Not working in thingiverse customizer atm [0:0.01:1]
// broke this out. if your keycaps are falling off lower this value. only works for cherry stems rn
$stem_inner_slop = 0.2;
// Font size used for text
$font_size = 6;
// Set this to true if you're making a spacebar!
$inverted_dish = false;
// change aggressiveness of double sculpting
// this is the radius of the cylinder the keytops are placed on
$double_sculpt_radius = 200;
// Support type. default is "flared" for easy FDM printing; bars are more realistic, and flat could be for artisans
$support_type = "flared"; // [flared, bars, flat, disable]
// Supports for the stem, as it often comes off during printing. Reccommended for most machines
$stem_support_type = "tines"; // [tines, brim, disabled]
// make legends outset instead of inset.
// broken off from artisan support since who wants outset legends?
$outset_legends = false;
/* [Key] */
// Height in units of key. should remain 1 for most uses
$key_height = 1.0;
// Keytop thickness, aka how many millimeters between the inside and outside of the top surface of the key
$keytop_thickness = 1;
// Wall thickness, aka the thickness of the sides of the keycap. note this is the total thickness, aka 3 = 1.5mm walls
$wall_thickness = 3;
// Radius of corners of keycap
$corner_radius = 1;
// Width of the very bottom of the key
$bottom_key_width = 18.16;
// Height (from the front) of the very bottom of the key
$bottom_key_height = 18.16;
// How much less width there is on the top. eg top_key_width = bottom_key_width - width_difference
$width_difference = 6;
// How much less height there is on the top
$height_difference = 4;
// How deep the key is, before adding a dish
$total_depth = 11.5;
// The tilt of the dish in degrees. divided by key height
$top_tilt = -6;
// the y tilt of the dish in degrees. divided by key width.
// for double axis sculpted keycaps and probably not much else
$top_tilt_y = 0;
// How skewed towards the back the top is (0 for center)
$top_skew = 1.7;
// how skewed towards the right the top is. unused, but implemented.
// for double axis sculpted keycaps and probably not much else
$top_skew_x = 0;
/* [Stem] */
// How far the throw distance of the switch is. determines how far the 'cross' in the cherry switch digs into the stem, and how long the keystem needs to be before supports can start. luckily, alps and cherries have a pretty similar throw. can modify to have stouter keycaps for low profile switches, etc
$stem_throw = 4;
// Diameter of the outside of the rounded cherry stem
$rounded_cherry_stem_d = 5.5;
// How much higher the stem is than the bottom of the keycap.
// Inset stem requires support but is more accurate in some profiles
$stem_inset = 0;
// How many degrees to rotate the stems. useful for sideways keycaps, maybe
$stem_rotation = 0;
// enable to have stem support extend past the keycap bottom, to (hopefully) the next
// keycap. only works on tines right now
$extra_long_stem_support = false;
/* [Shape] */
// Key shape type, determines the shape of the key. default is 'rounded square'
$key_shape_type = "rounded_square";
// ISO enter needs to be linear extruded NOT from the center. this tells the program how far up 'not from the center' is
$linear_extrude_height_adjustment = 0;
// How many slices will be made, to approximate curves on corners. Leave at 1 if you are not curving corners
// If you're doing fancy bowed keycap sides, this controls how many slices you take
$height_slices = 1;
/* [Dish] */
// What type of dish the key has. note that unlike stems and supports a dish ALWAYS gets rendered.
$dish_type = "cylindrical"; // [cylindrical, spherical, sideways cylindrical, old spherical, disable]
// How deep the dish 'digs' into the top of the keycap. this is max depth, so you can't find the height from total_depth - dish_depth. besides the top is skewed anyways
$dish_depth = 1;
// How skewed in the x direction the dish is
$dish_skew_x = 0;
// How skewed in the y direction (height) the dish is
$dish_skew_y = 0;
// If you need the dish to extend further, you can 'overdraw' the rectangle it will hit
$dish_overdraw_width = 0;
// Same as width but for height
$dish_overdraw_height = 0;
/* [Misc] */
// There's a bevel on the cherry stems to aid insertion / guard against first layer squishing making a hard-to-fit stem.
$cherry_bevel = true;
// How tall in mm the stem support is, if there is any. stem support sits around the keystem and helps to secure it while printing.
$stem_support_height = .8;
// Font used for text
$font="DejaVu Sans Mono:style=Book";
// Whether or not to render fake keyswitches to check clearances
$clearance_check = false;
// Should be faster, also required for concave shapes
// Use linear_extrude instead of hull slices to make the shape of the key
$linear_extrude_shape = false;
// warns in trajectory.scad but it looks benign
// brand new, more correct, hopefully faster, lots more work
$skin_extrude_shape = false;
// This doesn't work very well, but you can try
$rounded_key = false;
//minkowski radius. radius of sphere used in minkowski sum for minkowski_key function. 1.75 for G20
$minkowski_radius = .33;
/* [Features] */
//insert locating bump
$key_bump = false;
//height of the location bump from the top surface of the key
$key_bump_depth = 0.5;
//distance to move the bump from the front edge of the key
$key_bump_edge = 0.4;
/* [Hidden] */
// set this to true if you are making double sculpted keycaps
$double_sculpted = false;
//list of legends to place on a key format: [text, halign, valign, size]
//halign = "left" or "center" or "right"
//valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it
$legends = [];
//list of front legends to place on a key format: [text, halign, valign, size]
//halign = "left" or "center" or "right"
//valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it
$front_legends = [];
// print legends on the front of the key instead of the top
$front_print_legends = false;
// how recessed inset legends / artisans are from the top of the key
$inset_legend_depth = 0.2;
// Dimensions of alps stem
$alps_stem = [4.45, 2.25];
// Enable stabilizer stems, to hold onto your cherry or costar stabilizers
$stabilizer_type = "costar_stabilizer"; // [costar_stabilizer, cherry_stabilizer, disable]
// Ternaries are ONLY for customizer. they will NOT work if you're using this in
// OpenSCAD. you should use stabilized(), openSCAD customizer,
// or set $stabilizers directly
// Array of positions of stabilizers
$stabilizers = $key_length >= 6 ? [[-50, 0], [50, 0]] : $key_length >= 2 ? [[-12,0],[12,0]] : [];
// Where the stems are in relation to the center of the keycap, in units. default is one in the center
// Shouldn't work in thingiverse customizer, though it has been...
$stem_positions = [[0,0]];
// colors
$primary_color = [.2667,.5882,1];
$secondary_color = [.4412, .7, .3784];
$tertiary_color = [1, .6941, .2];
$quaternary_color = [.4078, .3569, .749];
$warning_color = [1,0,0, 0.15];
// key width functions
module u(u=1) {
$key_length = u;
children();
}
module 1u() {
u(1) children();
}
module 1_25u() {
u(1.25) children();
}
module 1_5u() {
u(1.5) children();
}
module 2u() {
u(2) children();
}
module 2_25u() {
u(2.25) children();
}
module 2_75u() {
u(2.75) children();
}
module 6_25u() {
u(6.25) children();
}
// key height functions
module uh(u=1) {
$key_height = u;
children();
}
module 1uh() {
uh(1) children();
}
module 2uh() {
uh(2) children();
}
module 1_25uh() {
uh(1.25) children();
}
module 1_5uh() {
uh(1.5) children();
}
module 2_25uh() {
uh(2.25) children();
}
module 2_75uh() {
uh(2.75) children();
}
module 6_25uh() {
uh(6.25) children();
}
// key profile definitions
// unlike the other files with their own dedicated folders, this one doesn't
// need a selector. I wrote one anyways for customizer support though
module dcs_row(row=3, column=0) {
$bottom_key_width = 18.16;
$bottom_key_height = 18.16;
$width_difference = 6;
$height_difference = 4;
$dish_type = "cylindrical";
$dish_depth = 0.5;
$dish_skew_x = 0;
$dish_skew_y = 0;
$top_skew = 1.75;
$top_tilt_y = side_tilt(column);
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;
// this dish depth should match the depth of the uberdishing in fully sculpted mode
// but it doesn't, and it's very slight for any reasonable double sculpting
/* $dish_depth = $double_sculpt_radius - sin(acos(top_total_key_width()/2 /$double_sculpt_radius)) * $double_sculpt_radius; */
/* echo("DISH DEPTH", $dish_depth, "column", column); */
// 5/0 is a hack so you can do these in a for loop
if (row == 5 || row == 0) {
$total_depth = 11.5 + extra_height;
$top_tilt = -6;
children();
} else if (row == 1) {
$total_depth = 8.5 + extra_height;
$top_tilt = -1;
children();
} else if (row == 2) {
$total_depth = 7.5 + extra_height;
$top_tilt = 3;
children();
} else if (row == 3) {
$total_depth = 6 + extra_height;
$top_tilt = 7;
children();
} else if (row == 4) {
$total_depth = 6 + extra_height;
$top_tilt = 16;
children();
} else {
children();
}
}
module oem_row(row=3, column = 0) {
$bottom_key_width = 18.05;
$bottom_key_height = 18.05;
$width_difference = 5.8;
$height_difference = 4;
$dish_type = "cylindrical";
$dish_depth = 1;
$dish_skew_x = 0;
$dish_skew_y = 0;
$top_skew = 1.75;
$stem_inset = 1.2;
$top_tilt_y = side_tilt(column);
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;
if (row == 5 || row == 0) {
$total_depth = 11.2 + extra_height;
$top_tilt = -3;
children();
} else if (row == 1) {
$total_depth = 9.45 + extra_height;
$top_tilt = 1;
children();
} else if (row == 2) {
$total_depth = 9 + extra_height;
$top_tilt = 6;
children();
} else if (row == 3) {
$total_depth = 9.25 + extra_height;
$top_tilt = 9;
children();
} else if (row == 4) {
$total_depth = 9.25 + extra_height;
$top_tilt = 10;
children();
} else {
children();
}
}
module dsa_row(row=3, column = 0) {
$key_shape_type = "sculpted_square";
$bottom_key_width = 18.24; // 18.4;
$bottom_key_height = 18.24; // 18.4;
$width_difference = 6; // 5.7;
$height_difference = 6; // 5.7;
$top_tilt = row == 5 ? -21 : (row-3) * 7;
$top_skew = 0;
$dish_type = "spherical";
$dish_depth = 1.2;
$dish_skew_x = 0;
$dish_skew_y = 0;
$height_slices = 10;
$enable_side_sculpting = true;
$corner_radius = 0.25;
$top_tilt_y = side_tilt(column);
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;
depth_raisers = [0, 3.5, 1, 0, 1, 3];
if (row < 1 || row > 4) {
$total_depth = 8.1 + depth_raisers[row] + extra_height;
children();
} else if (row == 1) {
$total_depth = 8.1 + depth_raisers[row] + extra_height;
children();
} else if (row == 2) {
$total_depth = 8.1 + depth_raisers[row] + extra_height;
children();
} else if (row == 3) {
$total_depth = 8.1 + depth_raisers[row] + extra_height;
children();
} else if (row == 4) {
$total_depth = 8.1 + depth_raisers[row] + extra_height;
children();
} else {
children();
}
}
module sa_row(n=3, column=0) {
$key_shape_type = "sculpted_square";
$bottom_key_width = 18.4;
$bottom_key_height = 18.4;
$width_difference = 5.7;
$height_difference = 5.7;
$dish_type = "spherical";
$dish_depth = 0.85;
$dish_skew_x = 0;
$dish_skew_y = 0;
$top_skew = 0;
$height_slices = 10;
// might wanna change this if you don't minkowski
// do you even minkowski bro
$corner_radius = 0.25;
// this is _incredibly_ intensive
/* $rounded_key = true; */
$top_tilt_y = side_tilt(column);
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;
// 5th row is usually unsculpted or the same as the row below it
// making a super-sculpted top row (or bottom row!) would be real easy
// bottom row would just be 13 tilt and 14.89 total depth
// top row would be something new entirely - 18 tilt maybe?
if (n <= 1){
$total_depth = 14.89 + extra_height;
$top_tilt = -13;
children();
} else if (n == 2) {
$total_depth = 12.925 + extra_height;
$top_tilt = -7;
children();
} else if (n == 3) {
$total_depth = 12.5 + extra_height;
$top_tilt = 0;
children();
} else if (n == 4){
$total_depth = 12.925 + extra_height;
$top_tilt = 7;
children();
} else {
$total_depth = 12.5 + extra_height;
$top_tilt = 0;
children();
}
}
module g20_row(row=3, column = 0) {
$bottom_key_width = 18.16;
$bottom_key_height = 18.16;
$width_difference = 2;
$height_difference = 2;
$top_tilt = 2.5;
$top_skew = 0.75;
$dish_type = "disable";
// something weird is going on with this and legends - can't put it below 1.2 or they won't show
$dish_depth = 1.2;
$dish_skew_x = 0;
$dish_skew_y = 0;
$minkowski_radius = 1.75;
$key_bump_depth = 0.6;
$key_bump_edge = 2;
//also,
$rounded_key = true;
$top_tilt_y = side_tilt(column);
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;
$total_depth = 6 + abs((row-3) * 0.5) + extra_height;
if (row == 5 || row == 0) {
$top_tilt = -18.55;
children();
} else if (row == 1) {
$top_tilt = (row-3) * 7 + 2.5;
children();
} else if (row == 2) {
$top_tilt = (row-3) * 7 + 2.5;
children();
} else if (row == 3) {
$top_tilt = (row-3) * 7 + 2.5;
children();
} else if (row == 4) {
$top_tilt = (row-3) * 7 + 2.5;
children();
} else {
children();
}
}
// my own measurements
module hipro_row(row=3, column=0) {
$key_shape_type = "sculpted_square";
$bottom_key_width = 18.35;
$bottom_key_height = 18.17;
$width_difference = ($bottom_key_width - 12.3);
$height_difference = ($bottom_key_height - 12.65);
$dish_type = "spherical";
$dish_depth = 0.75;
$dish_skew_x = 0;
$dish_skew_y = 0;
$top_skew = 0;
$height_slices = 10;
// might wanna change this if you don't minkowski
// do you even minkowski bro
$corner_radius = 0.25;
$top_tilt_y = side_tilt(column);
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;
if (row <= 1){
$total_depth = 13.7 + extra_height;
// TODO I didn't change these yet
$top_tilt = -13;
children();
} else if (row == 2) {
$total_depth = 11.1 + extra_height;
$top_tilt = -7;
children();
} else if (row == 3) {
$total_depth = 11.1 + extra_height;
$top_tilt = 7;
children();
} else if (row == 4 || row == 5){
$total_depth = 12.25 + extra_height;
$top_tilt = 13;
children();
} else {
children();
}
}
module grid_row(row=3, column = 0) {
$bottom_key_width = 18.16;
$bottom_key_height = 18.16;
$width_difference = 0.2;
$height_difference = 0.2;
$top_tilt = 0;
$top_skew = 0;
$dish_type = "old spherical";
// something weird is going on with this and legends - can't put it below 1.2 or they won't show
$dish_depth = 1;
$dish_skew_x = 0;
$dish_skew_y = 0;
$linear_extrude_shape = true;
$dish_overdraw_width = -8;
$dish_overdraw_height = -8;
$minkowski_radius = 0.5;
//also,
/* $rounded_key = true; */
$top_tilt_y = side_tilt(column);
extra_height = $double_sculpted ? extra_side_tilt_height(column) : 0;
$total_depth = 6 + abs((row-3) * 0.5) + extra_height;
if (row == 5 || row == 0) {
/* $top_tilt = -18.55; */
children();
} else if (row == 1) {
/* $top_tilt = (row-3) * 7 + 2.5; */
children();
} else if (row == 2) {
/* $top_tilt = (row-3) * 7 + 2.5; */
children();
} else if (row == 3) {
/* $top_tilt = (row-3) * 7 + 2.5; */
children();
} else if (row == 4) {
/* $top_tilt = (row-3) * 7 + 2.5; */
children();
} else {
children();
}
}
// man, wouldn't it be so cool if functions were first order
module key_profile(key_profile_type, row, column=0) {
if (key_profile_type == "dcs") {
dcs_row(row, column) children();
} else if (key_profile_type == "oem") {
oem_row(row, column) children();
} else if (key_profile_type == "dsa") {
dsa_row(row, column) children();
} else if (key_profile_type == "sa") {
sa_row(row, column) children();
} else if (key_profile_type == "g20") {
g20_row(row, column) children();
} else if (key_profile_type == "hipro") {
hipro_row(row, column) children();
} else if (key_profile_type == "grid") {
grid_row(row, column) children();
} else if (key_profile_type == "disable") {
children();
} else {
echo("Warning: unsupported key_profile_type");
}
}
module spacebar() {
$inverted_dish = true;
$dish_type = "sideways cylindrical";
6_25u() stabilized(mm=50) children();
}
module lshift() {
2_25u() stabilized() children();
}
module rshift() {
2_75u() stabilized() children();
}
module backspace() {
2u() stabilized() children();
}
module enter() {
2_25u() stabilized() children();
}
module numpad_enter() {
2uh() stabilized(vertical=true) children();
}
module numpad_plus() {
numpad_enter() children();
}
module numpad_0() {
backspace() children();
}
module stepped_caps_lock() {
u(1.75) {
$stem_positions = [[-5, 0]];
children();
}
}
module iso_enter() {
$key_length = 1.5;
$key_height = 2;
$top_tilt = 0;
$stem_support_type = "disable";
$key_shape_type = "iso_enter";
/* $linear_extrude_shape = true; */
$linear_extrude_height_adjustment = 19.05 * 0.5;
// this equals (unit_length(1.5) - unit_length(1.25)) / 2
$dish_overdraw_width = 2.38125;
stabilized(vertical=true) {
children();
}
}
// kind of a catch-all at this point for any directive that doesn't fit in the other files
//TODO duplicate def to not make this a special var. maybe not worth it
unit = 19.05;
module translate_u(x=0, y=0, z=0){
translate([x * unit, y*unit, z*unit]) children();
}
module no_stem_support() {
$stem_support_type = "disable";
children();
}
module brimmed_stem_support(height = 0.4) {
$stem_support_type = "brim";
$stem_support_height = height;
children();
}
module tined_stem_support(height = 0.4) {
$stem_support_type = "tines";
$stem_support_height = height;
children();
}
module unsupported_stem() {
$stem_support_type = "disable";
children();
}
module rounded() {
$rounded_key = true;
children();
}
module inverted() {
$inverted_dish = true;
children();
}
module rotated() {
$stem_rotation = 90;
children();
}
module stabilized(mm=12, vertical = false, type=undef) {
if (vertical) {
$stabilizer_type = (type ? type : ($stabilizer_type ? $stabilizer_type : "costar_stabilizer"));
$stabilizers = [
[0, mm],
[0, -mm]
];
children();
} else {
$stabilizer_type = (type ? type : ($stabilizer_type ? $stabilizer_type : "costar_stabilizer"));
$stabilizers = [
[mm, 0],
[-mm, 0]
];
children();
}
}
module dishless() {
$dish_type = "disable";
children();
}
module inset(val=1) {
$stem_inset = val;
children();
}
module filled() {
$stem_type = "filled";
children();
}
module blank() {
$stem_type = "disable";
children();
}
module cherry(slop) {
$stem_slop = slop ? slop : $stem_slop;
$stem_type = "cherry";
children();
}
module alps(slop) {
$stem_slop = slop ? slop : $stem_slop;
$stem_type = "alps";
children();
}
module rounded_cherry(slop) {
$stem_slop = slop ? slop : $stem_slop;
$stem_type = "rounded_cherry";
children();
}
module box_cherry(slop) {
$stem_slop = slop ? slop : $stem_slop;
$stem_type = "box_cherry";
children();
}
module flared_support() {
$support_type = "flared";
children();
}
module bar_support() {
$support_type = "bars";
children();
}
module flat_support() {
$support_type = "flat";
children();
}
module legend(text, position=[0,0], size=undef) {
font_size = size == undef ? $font_size : size;
$legends = [for(L=[$legends, [[text, position, font_size]]], a=L) a];
children();
}
module front_legend(text, position=[0,0], size=undef) {
font_size = size == undef ? $font_size : size;
$front_legends = [for(L=[$front_legends, [[text, position, font_size]]], a=L) a];
children();
}
module bump(depth=undef) {
$key_bump = true;
$key_bump_depth = depth == undef ? $key_bump_depth : depth;
children();
}
// kinda dirty, but it works
// might not work great with fully sculpted profiles yet
// NOTE: this needs to come after row declarations or it won't work
module upside_down() {
if ($stem_inner_slop != 0) {
echo("it is recommended you set inner stem slop to 0 when you use upside_down()");
}
$stem_support_type = "disable";
// $top_tilt*2 because top_placement rotates by top_tilt for us
// first rotate 180 to get the keycaps to face the same direction
rotate([0,0,180]) top_placement() rotate([180+$top_tilt*2,0,0]) {
children();
}
}
module sideways() {
$key_shape_type = "flat_sided_square";
$dish_overdraw_width = abs(extra_keytop_length_for_flat_sides());
extra_y_rotation = atan2($width_difference/2,$total_depth);
translate([0,0,cos(extra_y_rotation) * total_key_width()/2])
rotate([0,90 + extra_y_rotation ,0]) children();
}
// emulating the % modifier.
// since we use custom colors, just using the % modifier doesn't work
module debug() {
$primary_color = [0.5,0.5,0.5,0.2];
$secondary_color = [0.5,0.5,0.5,0.2];
$tertiary_color = [0.5,0.5,0.5,0.2];
$quaternary_color = [0.5,0.5,0.5,0.2];
%children();
}
module arrows(profile, rows = [4,4,4,3]) {
positions = [[0, 0], [1, 0], [2, 0], [1, 1]];
legends = ["←", "↓", "→", "↑"];
for (i = [0:3]) {
translate_u(positions[i].x, positions[i].y) key_profile(profile, rows[i]) legend(legends[i]) cherry() key(true);
}
}
module f_cluster(profile, row=5) {
legends = ["F1", "F2", "F3", "F4"];
for (i =[0:len(legends)-1]) {
translate_u(i) key_profile(profile, row) cherry() legend(legends[i]) key(true);
}
}
module wasd(profile, rows = [2,2,2,1]) {
positions = [[0, 0], [1, 0], [2, 0], [1, 1]];
legends = ["A", "S", "D", "W"];
for (i = [0:3]) {
translate_u(positions[i].x, positions[i].y) key_profile(profile, rows[i]) legend(legends[i]) cherry() key(true);
}
}
module row_profile(profile, unsculpted = false) {
rows = [5, 1, 2, 3, 4];
for(row = [0:len(rows)-1]) {
translate_u(0, -row) key_profile(profile, unsculpted ? 3 : rows[row]) children();
}
}
// files
SMALLEST_POSSIBLE = 1/128;
// I use functions when I need to compute special variables off of other special variables
// functions need to be explicitly included, unlike special variables, which
// just need to have been set before they are used. hence this file
// cherry stem dimensions
function outer_cherry_stem(slop) = [7.2 - slop * 2, 5.5 - slop * 2];
// cherry stabilizer stem dimensions
function outer_cherry_stabilizer_stem(slop) = [4.85 - slop * 2, 6.05 - slop * 2];
// box (kailh) switches have a bit less to work with
function outer_box_cherry_stem(slop) = [6 - slop, 6 - slop];
// .005 purely for aesthetics, to get rid of that ugly crosshatch
function cherry_cross(slop, extra_vertical = 0) = [
// horizontal tine
[4.03 + slop, 1.25 + slop / 3],
// vertical tine
[1.15 + slop / 3, 4.23 + extra_vertical + slop / 3 + SMALLEST_POSSIBLE],
];
// actual mm key width and height
function total_key_width(delta = 0) = $bottom_key_width + $unit * ($key_length - 1) - delta;
function total_key_height(delta = 0) = $bottom_key_height + $unit * ($key_height - 1) - delta;
// actual mm key width and height at the top
function top_total_key_width() = $bottom_key_width + ($unit * ($key_length - 1)) - $width_difference;
function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1)) - $height_difference;
function side_tilt(column) = asin($unit * column / $double_sculpt_radius);
// tan of 0 is 0, division by 0 is nan, so we have to guard
function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0;
// (I think) extra length of the side of the keycap due to the keytop being tilted.
// necessary for calculating flat sided keycaps
function vertical_inclination_due_to_top_tilt() = sin($top_tilt) * (top_total_key_height() - $corner_radius * 2) * 0.5;
// how much you have to expand the front or back of the keytop to make the side
// of the keycap a flat plane. 1 = front, -1 = back
// I derived this through a bunch of trig reductions I don't really understand.
function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_inclination_due_to_top_tilt()) / ($total_depth);
$fs=.1;
unit = 19.05;
// corollary is rounded_square
// NOT 3D
function unit_length(length) = unit * (length - 1) + 18.16;
module ISO_enter_shape(size, delta, progress){
width = size[0];
height = size[1];
// in order to make the ISO keycap shape generic, we are going to express the
// 'elbow point' in terms of ratios. an ISO enter is just a 1.5u key stuck on
// top of a 1.25u key, but since our key_shape function doesnt understand that
// and wants to pass just width and height, we make these ratios to know where
// to put the elbow joint
width_ratio = unit_length(1.25) / unit_length(1.5);
height_ratio = unit_length(1) / unit_length(2);
pointArray = [
[ 0, 0], // top right
[ 0, -height], // bottom right
[-width * width_ratio, -height], // bottom left
[-width * width_ratio,-height * height_ratio], // inner middle point
[ -width,-height * height_ratio], // outer middle point
[ -width, 0] // top left
];
minkowski(){
circle(r=corner_size);
// gives us rounded inner corner
offset(r=-corner_size*2) {
translate([(width * width_ratio)/2, height/2]) polygon(points=pointArray);
}
}
}
function iso_enter_vertices(width, height, width_ratio, height_ratio, wd, hd) = [
[ 0-wd, 0-hd], // top right
[ 0-wd, -height+hd], // bottom right
[-width * width_ratio+wd, -height+hd], // bottom left
[-width * width_ratio+wd,-height * height_ratio+hd], // inner middle point
[ -width+wd,-height * height_ratio+hd], // outer middle point
[ -width+wd, 0-hd] // top left
] + [
[(width * width_ratio)/2, height/2 ],
[(width * width_ratio)/2, height/2 ],
[(width * width_ratio)/2, height/2 ],
[(width * width_ratio)/2, height/2 ],
[(width * width_ratio)/2, height/2 ],
[(width * width_ratio)/2, height/2 ]
];
// no rounding on the corners at all
function skin_iso_enter_shape(size, delta, progress, thickness_difference) =
iso_enter_vertices(size.x, size.y, unit_length(1.25) / unit_length(1.5), unit_length(1) / unit_length(2), thickness_difference/2 + delta.x * progress/2, thickness_difference/2 + delta.y * progress/2);
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, fn) * [size[0]/2-r,0]
+ sign_y(index, fn) * [0,size[1]/2-r]
];
function sign_x(i,n) =
i < n/4 || i > n-n/4 ? 1 :
i > n/4 && i < n-n/4 ? -1 :
0;
function sign_y(i,n) =
i > 0 && i < n/2 ? 1 :
i > n/2 ? -1 :
0;
// rounded square shape with additional sculpting functions to better approximate
// When sculpting sides, how much in should the tops come
$side_sculpting_factor = 4.5;
// When sculpting corners, how much extra radius should be added
$corner_sculpting_factor = 1;
// When doing more side sculpting corners, how much extra radius should be added
$more_side_sculpting_factor = 0.4;