key V2 with modular design and nestable attributes

This commit is contained in:
Bob - Home - Windows 2017-08-12 01:10:48 -04:00
parent 1b16b9a916
commit 44da611cdd
10 changed files with 75658 additions and 575 deletions

50
dishes.scad Normal file
View File

@ -0,0 +1,50 @@
module cylindrical_dish(top_total_key_width, dish_depth, inverted_dish, top_tilt){
/* we do some funky math here
* basically you want to have the dish "dig in" to the keycap x millimeters
* in order to do that you have to solve a small (2d) system of equations
* where the chord of the spherical cross section of the dish is
* the width of the keycap.
*/
// the distance you have to move the dish so it digs in dish_depth millimeters
chord_length = (pow(top_total_key_width, 2) - 4 * pow(dish_depth, 2)) / (8 * dish_depth);
//the radius of the dish
rad = (pow(top_total_key_width, 2) + 4 * pow(dish_depth, 2)) / (8 * dish_depth);
direction = inverted_dish ? -1 : 1;
rotate([90-top_tilt,0,0]){
translate([0,chord_length * direction,0]){
cylinder(h=100,r=rad, $fn=1024, center=true);
}
}
}
module spherical_dish(top_total_key_width, dish_depth, inverted_dish, top_tilt){
//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
chord = pow((pow(top_total_key_width,2) + pow(top_total_key_height(), 2)),0.5); //getting diagonal of the top
// the distance you have to move the dish up so it digs in dish_depth millimeters
chord_length = (pow(chord, 2) - 4 * pow(dish_depth, 2)) / (8 * dish_depth);
//the radius of the dish
rad = (pow(chord, 2) + 4 * pow(dish_depth, 2)) / (8 * dish_depth);
direction = inverted_dish ? -1 : 1;
rotate([-top_tilt,0,0]){
translate([0,0,chord_length * direction]){
//NOTE: if your dish is long at all you might need to increase $fn
sphere(r=rad, $fn=512);
}
}
}
module sideways_cylindrical_dish(top_total_key_width, dish_depth, inverted_dish, top_tilt){
chord_length = (pow(top_total_key_height(), 2) - 4 * pow(dish_depth, 2)) / (8 * dish_depth);
rad = (pow(top_total_key_height(), 2) + 4 * pow(dish_depth, 2)) / (8 * dish_depth);
direction = inverted_dish ? -1 : 1;
rotate([90,top_tilt,90]){
translate([0,chord_length * direction,0]){
cylinder(h=total_key_width + 20,r=rad, $fn=1024, center=true); // +20 just cuz
}
}
}

758
key.scad
View File

@ -1,456 +1,96 @@
/* [Key] */ include <variables.scad>
include <util.scad>
include <stems.scad>
include <dishes.scad>
/* [Settings] */
// 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;
/* [Brim] */
//brim radius. 11 ensconces normal keycap stem in normal keycap
brim_radius = 8;
//brim depth
brim_depth = .3;
//whether stabilizer connectors are enabled
stabilizers = false;
// how inset the stem is from the bottom of the key. experimental. requires support
stem_inset = 0;
// stem offset in units NOT MM. for stepped caps lock basically
stem_offset = 0;
/* [Key profile] */
// width of the very bottom of the key
bottom_key_width = 18.16;
// height (from the front) of the very bottom of the ke
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;
// how skewed towards the back the top is (0 for center)
top_skew = 1.7;
// what type of dish the key has. 0 for cylindrical, 1 for spherical, 2 for something else idk TODO
dish_type = 0;
// 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;
//length in units of key //length in units of key
key_length = 1; key_length = 1;
//height in units of key. should remain 1 for most uses //height in units of key. should remain 1 for most uses
key_height = 1; key_height = 1;
//keycap type, [0:DCS Row 5, 1:DCS Row 1, 2:DCS Row 2, 3:DCS Row 3, 4:DCS Row 4, 5:DSA Row 3, 6:SA Row 1, 7:SA Row 2, 8:SA Row 3, 9:SA Row 4, 10:DCS Row 4 Spacebar, 11: g20 key (faked)] //print brim for connector to help with bed adhesion
key_profile_index = 0; has_brim = false;
// 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;
/* [Brim] */
//enable brim for connector
has_brim = 0;
//brim radius. 11 ensconces normal keycap stem in normal keycap
brim_radius = 11;
//brim depth
brim_depth = .3;
/* [Stabilizers] */
//whether stabilizer connectors are enabled
stabilizers = 0;
//stabilizer distance in mm
stabilizer_distance = 50;
/* [Dish] */
// invert dishing. mostly for spacebar // invert dishing. mostly for spacebar
inverted_dish = 0; inverted_dish = false;
// array of positions of all stems. includes stabilizers as well, for now
/* [Stem] */ // ternary is a bad hack to keep the stabilizers flag working
connectors = stabilizers ? [[0,0],[-50,0],[50,0]] : [[0,0]];
// whether or not we use the functions to generate an ISO enter
// NOTE this uses data in the profile so be sure to set the profile to ISO enter too
ISOEnter = false;
//should the key be rounded? unnecessary for most printers, and very slow
rounded_key = false;
// cherry MX or Alps stem, or totally broken circular cherry stem [0..2] // cherry MX or Alps stem, or totally broken circular cherry stem [0..2]
stem_profile = 0; stem_profile = 0;
// how inset the stem is from the bottom of the key. experimental. requires support
stem_inset = 0;
// stem offset in units NOT MM. for stepped caps lock
stem_offset = 0;
/* [Hidden] */ /* [Hidden] */
//change to round things better //change to round things better
$fn = 32; $fn = 32;
//beginning to use unit instead of baked in 19.05 //beginning to use unit instead of baked in 19.05
unit = 19.05; unit = 19.05;
//minkowski radius. radius of sphere used in minkowski sum for minkowski_key function. 1.75 default for faux G20 //minkowski radius. radius of sphere used in minkowski sum for minkowski_key function. 1.75 default for faux G20
minkowski_radius = 1.75; minkowski_radius = 1.75;
//profile specific stuff
/*
Here we have, for lack of a better implementation, an array
that defines the more intimate aspects of a key.
order is thus:
1. Bottom Key Width: width of the immediate bottom of the key
2. Bottom Key Height: height of the immediate bottom of the key
3. Top Key Width Difference: mm to subtract from bottom key width to create top key width
4. Top Key Height Difference: mm to subtract from bottom key height to create top key height
5. total Depth: how tall the total in the switch is before dishing
6. Top Tilt: X rotation of the top. Top and dish obj are rotated
7. Top Skew: Y skew of the top of the key relative to the bottom. DCS has some, DSA has none (its centered)
8. Dish Type: type of dishing. check out dish function for the options
9. Dish Depth: how many mm to cut into the key with
10. Dish Radius: radius of dish obj, the Sphere or Cylinder that cuts into the keycap
*/
key_profiles = [
//DCS Profile
[ //DCS ROW 5
18.16, // Bottom Key Width
18.16, // Bottom Key Height
6, // Top Key Width Difference
4, // Top Key Height Difference
11.5, // total Depth
-6, // Top Tilt
1.75,// Top Skew
//Dish Profile
0, // Dish Type
1, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //DCS ROW 1
18.16, // Bottom Key Width
18.16, // Bottom Key Height
6, // Top Key Width Difference
4, // Top Key Height Difference
8.5, // total Depth
-1, // Top Tilt
1.75,// Top Skew
//Dish Profile
0, // Dish Type
1, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //DCS ROW 2
18.16, // Bottom Key Width
18.16, // Bottom Key Height
6.2, // Top Key Width Difference
4, // Top Key Height Difference
7.5, // total Depth
3, // Top Tilt
1.75,// Top Skew
//Dish Profile
0, // Dish Type
1, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //DCS ROW 3
18.16, // Bottom Key Width
18.16, // Bottom Key Height
6, // Top Key Width Difference
4, // Top Key Height Difference
6.2, // total Depth
7, // Top Tilt
1.75,// Top Skew
//Dish Profile
0, // Dish Type
1, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //DCS ROW 4
18.16, // Bottom Key Width
18.16, // Bottom Key Height
6, // Top Key Width Difference
4, // Top Key Height Difference
6.2, // total Depth
16, // Top Tilt
1.75,// Top Skew
//Dish Profile
0, // Dish Type
1, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
//DSA Profile
[ //DSA ROW 3
18.4, // Bottom Key Width
18.4, // Bottom Key Height
5.7, // Top Key Width Difference
5.7, // Top Key Height Difference
7.4, // total Depth
0, // Top Tilt
0, // Top Skew
//Dish Profile
1, // Dish Type
1.2, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
//SA Proile
[ //SA ROW 1
18.4, // Bottom Key Width
18.4, // Bottom Key Height
5.7, // Top Key Width Difference
5.7, // Top Key Height Difference
13.73, // total Depth, fudged
-14, // Top Tilt
0, // Top Skew
//Dish Profile
1, // Dish Type
1.2, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //SA ROW 2
18.4, // Bottom Key Width
18.4, // Bottom Key Height
5.7, // Top Key Width Difference
5.7, // Top Key Height Difference
11.73, // total Depth
-7, // Top Tilt
0, // Top Skew
//Dish Profile
1, // Dish Type
1.2, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //SA ROW 3
18.4, // Bottom Key Width
18.4, // Bottom Key Height
5.7, // Top Key Width Difference
5.7, // Top Key Height Difference
11.73, // total Depth
0, // Top Tilt
0, // Top Skew
//Dish Profile
1, // Dish Type
1.2, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //SA ROW 4
18.4, // Bottom Key Width
18.4, // Bottom Key Height
5.7, // Top Key Width Difference
5.7, // Top Key Height Difference
11.73, // total Depth
7, // Top Tilt
0, // Top Skew
//Dish Profile
1, // Dish Type
1.2, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //DCS ROW 4 SPACEBAR
18.16, // Bottom Key Width
18.16, // Bottom Key Height
6, // Top Key Width Difference
4, // Top Key Height Difference
6.2, // total Depth
16, // Top Tilt
1.75,// Top Skew
//Dish Profile
2, // Dish Type
1, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //G20 AKA DCS Row 2 with no dish and shorter
18.16, // Bottom Key Width
18.16, // Bottom Key Height
2, // Top Key Width Difference
2, // Top Key Height Difference
6, // total Depth
2.5, // Top Tilt
1,// Top Skew
//Dish Profile
3, // Dish Type
0, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
[ //NONWORKING fake ISO enter
18.16 * 1.5, // Bottom Key Width
18.16 * 2, // Bottom Key Height
4, // Top Key Width Difference
4, // Top Key Height Difference
7, // total Depth
0, // Top Tilt
1.75,// Top Skew
//Dish Profile
0, // Dish Type
1, // Dish Depth
0, // Dish Skew X
0 // DIsh Skew Y
],
];
// derived variables // derived variables
//key profile selected
key_profile = key_profiles[key_profile_index];
// names, so I don't go crazy
bottom_key_width = key_profile[0];
bottom_key_height = key_profile[1];
width_difference = key_profile[2];
height_difference = key_profile[3];
total_depth = key_profile[4];
top_tilt = key_profile[5] / key_height;
top_skew = key_profile[6];
dish_type = key_profile[7];
dish_depth = key_profile[8];
dish_skew_x = key_profile[9];
dish_skew_y = key_profile[10];
// actual mm key width and height // actual mm key width and height
total_key_width = bottom_key_width + (unit * (key_length - 1)); function total_key_width() = $bottom_key_width + (unit * ($key_length - 1));
total_key_height = bottom_key_height + (unit * (key_height - 1)); function total_key_height() = $bottom_key_height + (unit * ($key_height - 1));
// actual mm key width and height at the top // actual mm key width and height at the top
top_total_key_width = bottom_key_width + (unit * (key_length - 1)) - width_difference; function top_total_key_width() = $bottom_key_width + (unit * ($key_length - 1)) - $width_difference;
top_total_key_height = bottom_key_height + (unit * (key_height - 1)) - height_difference; function top_total_key_height() = $bottom_key_height + (unit * ($key_height - 1)) - $height_difference;
//centered // bottom clipping shape we can use to anchor the stem, just a big ol cube with the inside of
module roundedRect(size, radius) {
x = size[0];
y = size[1];
z = size[2];
translate([-x/2,-y/2,0])
linear_extrude(height=z)
hull() {
translate([radius, radius, 0])
circle(r=radius);
translate([x - radius, radius, 0])
circle(r=radius);
translate([x - radius, y - radius, 0])
circle(r=radius);
translate([radius, y - radius, 0])
circle(r=radius);
}
}
// stem related stuff
// bottom we can use to anchor the stem, just a big ol cube with the inside of
// the keycap hollowed out // the keycap hollowed out
module inside(){ module inside(){
difference(){ difference(){
//TODO why 50?
translate([0,0,50]) cube([100000,100000,100000],center=true); translate([0,0,50]) cube([100000,100000,100000],center=true);
// NOTE: you're saying hey, if this is the inside why aren't we doing shape(wall_thickness, keytop_thickness);
// wall_thickness, keytop_thickness? well first off congratulations for
// figuring that out cuz it's a rat's nest in here. second off
// due to how the minkowski_key function works that isn't working out right
// now. it's a simple change if is_minkowski is implemented though
shape(0, 0);
}
}
module cherry_stem(){
// cross length
cross_length = 4.4;
//extra vertical cross length - the extra length of the up/down bar of the cross
extra_vertical_cross_length = 1.1;
//dimensions of connector
// outer cross extra length in x
extra_outer_cross_width = 2.10;
// outer cross extra length in y
extra_outer_cross_height = 1.0;
// dimensions of cross
// horizontal cross bar width
horizontal_cross_width = 1.4;
// vertical cross bar width
vertical_cross_width = 1.3;
// cross depth, stem height is 3.4mm
cross_depth = 4;
difference(){
union(){
if (stem_profile != 2){
translate([
-(cross_length+extra_outer_cross_width)/2,
-(cross_length+extra_outer_cross_height)/2,
stem_inset
])
cube([ // the base of the stem, the part the cruciform digs into
cross_length+extra_outer_cross_width,
cross_length+extra_outer_cross_height,
50
]);
} else {
cylinder(
d = cross_length+extra_outer_cross_height,
h = 50
);
}
if (has_brim == 1){ cylinder(r=brim_radius,h=brim_depth); }
}
//the cross part of the steam
translate([0,0,(cross_depth)/2 + stem_inset]){
cube([vertical_cross_width,cross_length+extra_vertical_cross_length,cross_depth], center=true );
cube([cross_length,horizontal_cross_width,cross_depth], center=true );
}
}
}
module alps_stem(){
cross_depth = 40;
width = 4.45;
height = 2.25;
base_width = 12;
base_height = 15;
translate([0,0,cross_depth/2 + stem_inset]){
cube([width,height,cross_depth], center = true);
}
}
//whole connector, alps or cherry, trimmed to fit
module connector(has_brim){
difference(){
//TODO can I really not do an array index here?
translate([-unit * stem_offset, 0, 0])
union(){
if(stem_profile == 0 || stem_profile == 2) cherry_stem();
if(stem_profile == 1) alps_stem();
}
inside();
}
}
//stabilizer connectors
module stabilizer_connectors(has_brim){
translate([stabilizer_distance,0,0]) connector(has_brim);
translate([-stabilizer_distance,0,0]) connector(has_brim);
}
//shape related stuff
//general shape of key. used for inside and outside
module shape(thickness_difference, depth_difference){
if (inverted_dish == 1){
difference(){
union(){
shape_hull(thickness_difference, depth_difference, 1);
dish(depth_difference);
}
outside(thickness_difference);
}
} else{
difference(){
shape_hull(thickness_difference, depth_difference, 1);
dish(depth_difference);
}
} }
} }
@ -463,130 +103,139 @@ module outside(thickness_difference){
} }
} }
// super basic hull shape without dish //key shape including dish. used as the ouside and inside shape in key()
module shape(thickness_difference, depth_difference){
difference(){
union(){
shape_hull(thickness_difference, depth_difference, 1);
if ($inverted_dish) { dish(depth_difference); }
}
if (!$inverted_dish) { dish(depth_difference); }
outside(thickness_difference);
}
}
// shape of the key but with soft, rounded edges. much more realistic, much more complex
module rounded_shape() {
minkowski(){
shape(minkowski_radius*2, minkowski_radius);
difference(){
sphere(r=minkowski_radius, $fn=24);
translate([0,0,-minkowski_radius])
cube([2*minkowski_radius,2*minkowski_radius,2*minkowski_radius], center=true);
}
}
}
// basic key shape, no dish, no inside
// modifier multiplies the height and top differences of the shape, // modifier multiplies the height and top differences of the shape,
// which is only used for dishing to cut the dish off correctly // which is only used for dishing to cut the dish off correctly
// height_difference used for keytop thickness // $height_difference used for keytop thickness
module shape_hull(thickness_difference, depth_difference, modifier){ module shape_hull(thickness_difference, depth_difference, modifier){
if ($ISOEnter) {
ISOEnterShapeHull(thickness_difference, depth_difference, modifier);
} else {
hull(){ hull(){
// bottom_key_width + (key_length -1) * unit is the correct length of the // $bottom_key_width + ($key_length -1) * unit is the correct length of the
// key. only 1u of the key should be bottom_key_width long; all others // key. only 1u of the key should be $bottom_key_width long; all others
// should be 1u // should be 1u
roundedRect([total_key_width - thickness_difference, total_key_height - thickness_difference, .001],1.5); roundedRect([total_key_width() - thickness_difference, total_key_height() - thickness_difference, .001],1.5);
//height_difference outside of modifier because that doesnt make sense //depth_difference outside of modifier because that doesnt make sense
translate([0,top_skew,total_depth * modifier - depth_difference]) translate([0,$top_skew,$total_depth * modifier - depth_difference]){
rotate([-top_tilt,0,0]) rotate([-$top_tilt / $key_height,0,0]){
roundedRect([total_key_width - thickness_difference - width_difference * modifier, total_key_height - thickness_difference - height_difference * modifier, .001],1.5); roundedRect([
total_key_width() - thickness_difference - $width_difference * modifier,
total_key_height() - thickness_difference - $height_difference * modifier,
.001
],1.5);
}
}
}
} }
} }
//dish related stuff
//dish selector //dish selector
module dish(depth_difference){ module dish(depth_difference){
if(dish_type == 0){ // cylindrical dish translate([$dish_skew_x, $top_skew + $dish_skew_y, $total_depth - depth_difference]){
cylindrical_dish(depth_difference); if($dish_type == 0){ // cylindrical dish
cylindrical_dish(top_total_key_width(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
} }
else if (dish_type == 1) { // spherical dish else if ($dish_type == 1) { // spherical dish
spherical_dish(depth_difference); spherical_dish(top_total_key_width(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
} }
else if (dish_type == 2){ // SIDEWAYS cylindrical dish - used for spacebar else if ($dish_type == 2){ // SIDEWAYS cylindrical dish - used for spacebar
sideways_cylindrical_dish(depth_difference); sideways_cylindrical_dish(top_total_key_width(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
} }
else if (dish_type == 3){ // else no dish
// no dish
} }
} }
module cylindrical_dish(depth_difference){ //whole connector, alps or cherry, trimmed to fit
/* we do some funky math here module connector(){
* basically you want to have the dish "dig in" to the keycap x millimeters
* in order to do that you have to solve a small (2d) system of equations
* where the chord of the spherical cross section of the dish is
* the width of the keycap.
*/
// the distance you have to move the dish up so it digs in dish_depth millimeters
chord_length = (pow(top_total_key_width, 2) - 4 * pow(dish_depth, 2)) / (8 * dish_depth);
//the radius of the dish
rad = (pow(top_total_key_width, 2) + 4 * pow(dish_depth, 2)) / (8 * dish_depth);
if (inverted_dish == 1){
translate([dish_skew_x, top_skew + dish_skew_y, total_depth - depth_difference])
rotate([90-top_tilt,0,0])
translate([0,-chord_length,0])
cylinder(h=100,r=rad, $fn=1024, center=true);
}
else{
translate([dish_skew_x, top_skew + dish_skew_y, total_depth - depth_difference])
rotate([90-top_tilt,0,0])
translate([0,chord_length,0])
cylinder(h=100,r=rad, $fn=1024, center=true);
}
}
module spherical_dish(depth_difference){
//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
chord = pow((pow(top_total_key_width,2) + pow(top_total_key_height, 2)),0.5); //getting diagonal of the top
// the distance you have to move the dish up so it digs in dish_depth millimeters
chord_length = (pow(chord, 2) - 4 * pow(dish_depth, 2)) / (8 * dish_depth);
//the radius of the dish
rad = (pow(chord, 2) + 4 * pow(dish_depth, 2)) / (8 * dish_depth);
if (inverted_dish == 1){
translate([dish_skew_x, top_skew + dish_skew_y, total_depth - depth_difference])
rotate([-top_tilt,0,0])
translate([0,0,-chord_length])
//NOTE: if your dish is long at all you might need to increase this number
sphere(r=rad, $fn=512);
}
else{
translate([dish_skew_x, top_skew + dish_skew_y, total_depth - depth_difference])
rotate([-top_tilt,0,0])
translate([0,0,chord_length])
sphere(r=rad, $fn=256);
}
}
module sideways_cylindrical_dish(depth_difference){
chord_length = (pow(top_total_key_height, 2) - 4 * pow(dish_depth, 2)) / (8 * dish_depth);
rad = (pow(top_total_key_height, 2) + 4 * pow(dish_depth, 2)) / (8 * dish_depth);
if (inverted_dish == 1){
translate([dish_skew_x, top_skew + dish_skew_y, total_depth - depth_difference])
rotate([90,top_tilt,90])
translate([0,-chord_length,0])
cylinder(h=total_key_width + 20,r=rad, $fn=1024, center=true); // +20 just cuz
}
else{
translate([dish_skew_x, top_skew + dish_skew_y, total_depth - depth_difference])
rotate([90,top_tilt,90])
translate([0,chord_length,0])
cylinder(h=total_key_width + 20,r=rad, $fn=1024, center=true);
}
}
//actual full key with space carved out and keystem/stabilizer connectors
module key(){
union(){
difference(){ difference(){
if($stem_profile == 0) {
cherry_stem();
} else if ($stem_profile == 1) {
alps_stem();
} else if ($stem_profile == 2) {
cherry_stem_rounded();
}
inside();
}
}
module brim() {
cylinder(r=brim_radius,h=brim_depth);
}
module keytop() {
echo($key_length);
difference(){
if ($rounded_key) {
rounded_shape();
} else {
shape(0, 0); shape(0, 0);
}
shape(wall_thickness, keytop_thickness); shape(wall_thickness, keytop_thickness);
} }
} }
connector(has_brim); //actual full key with space carved out and keystem/stabilizer connectors
// this is an example key with all the fixins
module key(){
$bottom_key_width = bottom_key_width;
$bottom_key_height = bottom_key_height;
$width_difference = width_difference;
$height_difference = height_difference;
$total_depth = total_depth;
$top_tilt = top_tilt;
$top_skew = top_skew;
$dish_type = dish_type;
$dish_depth = dish_depth;
$dish_skew_x = dish_skew_x;
$dish_skew_y = dish_skew_y;
$key_length = key_length;
$key_height = key_height;
$has_brim = has_brim;
$inverted_dish = inverted_dish;
$connectors = connectors;
$ISOEnter = ISOEnter;
$rounded_key = rounded_key;
$stem_profile = stem_profile;
if (stabilizers == 1){
stabilizer_connectors(has_brim); keytop();
//TODO this stem offset thing is weird here. find a better place for it. its for stepped caps lock
translate([-unit * stem_offset, 0, 0]){
for (x = $connectors) {
translate(x) connector();
}
}
if ($has_brim){
brim();
} }
} }
@ -600,60 +249,30 @@ difference(){
//minkowski_key(); //minkowski_key();
// Experimental stuff // Experimental stuff
// key rounded with minkowski sum. still supports wall and keytop thickness.
// use in actual output section. takes a long time to render with dishes.
// required for keycap 11, G20 keycap.
module minkowski_key(){
union(){
difference(){
minkowski(){
shape(minkowski_radius*2, minkowski_radius);
difference(){
sphere(r=minkowski_radius, $fn=24);
translate([0,0,-minkowski_radius])
cube([2*minkowski_radius,2*minkowski_radius,2*minkowski_radius], center=true);
}
}
shape(wall_thickness, keytop_thickness);
}
}
connector(has_brim);
if (stabilizers == 1){
stabilizer_connectors(has_brim);
}
}
// NOT 3D, NOT CENTERED // NOT 3D, NOT CENTERED
// corollary is roundedRect // corollary is roundedRect
module fakeISOEnter(thickness_difference){ module fakeISOEnter(thickness_difference){
z = 0.001; z = 0.001;
radius = 2; radius = 2;
/*TODO I figured it out. 18.16 is the actual keycap width / height, // 1u is the space taken upy by a 1u keycap.
whereas 19.01 is the unit. ISO enter obeys that just like everything else, // unit is the space taken up by a unit space for a keycap.
which means that it's height is 18.16 * 2 + (19.01 - 18.16) or, two // formula is 1u + unit *(length - 1)
keycap heights plus the space between them, also known as 18.16 +
(19.01 * (key_height - 1)). this is followed by the width too. should fix
to make this finally work*/
unit = 18.16; // TODO probably not
// t is all modifications to the polygon array // t is all modifications to the polygon array
// could do map but can scad even do map?
t = radius + thickness_difference/2; t = radius + thickness_difference/2;
function unit(length) = 19.02 * (length) + (18.16 - 19.02);
pointArray = [ pointArray = [
[ 0 + t, 0 + t], [ 0 + t, 0 + t],
[unit*1.25 - t, 0 + t], [unit(1.5) - t, 0 + t],
[unit*1.25 - t, unit*2 - t], [unit(1.5) - t, unit(1) - t],
[unit*-.25 + t, unit*2 - t], [unit(1.25) - t, unit(1) - t],
[unit*-.25 + t, unit*1 + t], [unit(1.25) - t, unit(2) - t],
[0 + t, unit*1 + t] [ 0 + t, unit(2) - t]
]; ];
minkowski(){ minkowski(){
@ -664,12 +283,11 @@ module fakeISOEnter(thickness_difference){
//corollary is shape_hull //corollary is shape_hull
module ISOEnterShapeHull(thickness_difference, depth_difference, modifier){ module ISOEnterShapeHull(thickness_difference, depth_difference, modifier){
unit = 18.16; // TODO probably not function unit(length) = 19.02 * (length) + (18.16 - 19.02);
height = 8 - depth_difference; height = 8 - depth_difference;
length = 1.5 * unit; // TODO not used. need for dish
translate([-0.125 * unit, unit*.5]) linear_extrude(height=height*modifier, scale=[.8, .9]){ translate([unit(-0.25), unit(.5)]) linear_extrude(height=height*modifier, scale=[.8, .9]){
translate([-unit*.5, -unit*1.5]) minkowski(){ translate([unit(-.5), unit(-1.5)]) minkowski(){
fakeISOEnter(thickness_difference); fakeISOEnter(thickness_difference);
} }
} }

14422
key.scad.stl Normal file

File diff suppressed because it is too large Load Diff

120
key_mold.scad Normal file
View File

@ -0,0 +1,120 @@
//key unit size
unit = 19.05;
//height of keycap
height = 13;
//minimum mold thickness
extra = 15;
//thicknesses of the mold
side_thickness = 2;
bottom_thickness = 2;
total_side = unit + extra*2 + side_thickness * 2;
function hypo(num) = sqrt(pow(num,2) / 2);
module bottom_mold(){
difference(){
//outer box
cube([
total_side,
total_side,
5 + bottom_thickness,
]);
//inner box
translate([
side_thickness,
side_thickness,
bottom_thickness
]) {
cube([
unit + extra*2,
unit + extra*2,
5,
]);
}
}
translate([total_side / 2, total_side / 2, 5 + bottom_thickness]) rotate([0,0,45]) difference(){
//outer box
cylinder(
height + extra - 5,
hypo(total_side),
hypo(total_side + 3),
$fn=4
);
//inner box
cylinder(
height + extra - 5,
hypo(unit + extra*2),
hypo(unit + extra*2 + 3),
$fn=4
);
}
//platform
translate([
side_thickness + extra,
side_thickness + extra,
bottom_thickness
]) cube([unit, unit, bottom_thickness]);
/*
translate([
side_thickness + extra + unit / 2,
side_thickness + extra + unit / 2,
bottom_thickness*2
]) rotate([0,0,45]) cylinder(bottom_thickness, unit/2 + 1, unit / 2, $fn=4);*/
//registration
translate([
side_thickness + extra / 2,
side_thickness + extra / 2,
bottom_thickness
]) cylinder(3,extra/3, extra/4, $fn=4);
//registration
translate([
side_thickness + extra / 2,
side_thickness + unit + extra * 1.5,
bottom_thickness
]) cylinder(3,extra/3, extra/4, $fn=4);
//registration
translate([
side_thickness + unit + extra * 1.5,
side_thickness + unit + extra * 1.5,
bottom_thickness
]) cylinder(3,extra/3, extra/4, $fn=4);
}
module top_mold(){
difference(){
//outer box
cube([
total_side,
total_side,
height + extra + bottom_thickness,
]);
//inner box
translate([
side_thickness,
side_thickness,
0
]) {
cube([
unit + extra*2,
unit + extra*2,
height + extra + bottom_thickness,
]);
}
}
}
/*bottom_mold();*/
translate([50,0,0]) top_mold();

226
key_mold.scad.stl Normal file
View File

@ -0,0 +1,226 @@
solid OpenSCAD_Model
facet normal -1 0 0
outer loop
vertex 50 0 0
vertex 50 53.05 30
vertex 50 53.05 0
endloop
endfacet
facet normal -1 -0 0
outer loop
vertex 50 53.05 30
vertex 50 0 0
vertex 50 0 30
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 103.05 53.05 30
vertex 101.05 51.05 30
vertex 103.05 0 30
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 103.05 53.05 30
vertex 52 51.05 30
vertex 101.05 51.05 30
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 52 51.05 30
vertex 50 53.05 30
vertex 52 2 30
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 50 53.05 30
vertex 52 51.05 30
vertex 103.05 53.05 30
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 101.05 2 30
vertex 103.05 0 30
vertex 101.05 51.05 30
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 52 2 30
vertex 103.05 0 30
vertex 101.05 2 30
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 52 2 30
vertex 50 0 30
vertex 103.05 0 30
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 50 0 30
vertex 52 2 30
vertex 50 53.05 30
endloop
endfacet
facet normal 1 -0 0
outer loop
vertex 103.05 0 30
vertex 103.05 53.05 0
vertex 103.05 53.05 30
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 103.05 53.05 0
vertex 103.05 0 30
vertex 103.05 0 0
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 103.05 53.05 0
vertex 50 53.05 30
vertex 103.05 53.05 30
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 50 53.05 30
vertex 103.05 53.05 0
vertex 50 53.05 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 103.05 0 0
vertex 101.05 2 0
vertex 103.05 53.05 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 103.05 0 0
vertex 52 2 0
vertex 101.05 2 0
endloop
endfacet
facet normal -0 0 -1
outer loop
vertex 52 2 0
vertex 50 0 0
vertex 52 51.05 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 50 0 0
vertex 52 2 0
vertex 103.05 0 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 101.05 51.05 0
vertex 103.05 53.05 0
vertex 101.05 2 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 52 51.05 0
vertex 103.05 53.05 0
vertex 101.05 51.05 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 52 51.05 0
vertex 50 53.05 0
vertex 103.05 53.05 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 50 53.05 0
vertex 52 51.05 0
vertex 50 0 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 50 0 0
vertex 103.05 0 30
vertex 50 0 30
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 103.05 0 30
vertex 50 0 0
vertex 103.05 0 0
endloop
endfacet
facet normal 1 -0 0
outer loop
vertex 52 2 30
vertex 52 51.05 0
vertex 52 51.05 30
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 52 51.05 0
vertex 52 2 30
vertex 52 2 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 101.05 2 0
vertex 101.05 51.05 30
vertex 101.05 51.05 0
endloop
endfacet
facet normal -1 -0 0
outer loop
vertex 101.05 51.05 30
vertex 101.05 2 0
vertex 101.05 2 30
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 52 51.05 0
vertex 101.05 51.05 30
vertex 52 51.05 30
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 101.05 51.05 30
vertex 52 51.05 0
vertex 101.05 51.05 0
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 101.05 2 0
vertex 52 2 30
vertex 101.05 2 30
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 52 2 30
vertex 101.05 2 0
vertex 52 2 0
endloop
endfacet
endsolid OpenSCAD_Model

335
keys.scad Normal file
View File

@ -0,0 +1,335 @@
use <key.scad>
//TODO duplicate def to not make this a special var. maybe not worth it
unit = 19.05;
// defaults
$bottom_key_width = 18.16;
$bottom_key_height = 18.16;
$width_difference = 6;
$height_difference = 4;
$total_depth = 11.5;
$top_tilt = -6;
$top_skew = 1.7;
$dish_type = 0;
$dish_depth = 1;
$dish_skew_x = 0;
$dish_skew_y = 0;
$key_length = 1;
$key_height = 1;
$has_brim = false;
$inverted_dish = false;
$connectors = [[0,0]];
$ISOEnter = false;
$rounded_key = false;
$stem_profile = 0;
// key profile definitions
module dcs_row(n=1) {
echo(n);
// names, so I don't go crazy
$bottom_key_width = 18.16;
$bottom_key_height = 18.16;
$width_difference = 6;
$height_difference = 4;
$dish_type = 0;
$dish_depth = 1;
$dish_skew_x = 0;
$dish_skew_y = 0;
if (n == 5) {
$total_depth = 11.5;
$top_tilt = -6;
$top_skew = 1.7;
children();
} else if (n == 1) {
$total_depth = 8.5;
$top_tilt = -1;
$top_skew = 1.75;
children();
} else if (n == 2) {
$total_depth = 7.5;
$top_tilt = 3;
$top_skew = 1.75;
children();
} else if (n == 3) {
$total_depth = 6;
$top_tilt = 7;
$top_skew = 1.75;
children();
} else if (n == 4) {
$total_depth = 6;
$top_tilt = 16;
$top_skew = 1.75;
children();
}
}
module dsa_row(n=3) {
$bottom_key_width = 18.4;
$bottom_key_height = 18.4;
$width_difference = 5.7;
$height_difference = 5.7;
$total_depth = 7.4;
$top_tilt = 0;
$top_skew = 0;
$dish_type = 1;
$dish_depth = 1.2;
$dish_skew_x = 0;
$dish_skew_y = 0;
children();
}
module sa_row(n=1) {
$bottom_key_width = 18.4;
$bottom_key_height = 18.4;
$width_difference = 5.7;
$height_difference = 5.7;
$dish_type = 1;
$dish_depth = 1.2;
$dish_skew_x = 0;
$dish_skew_y = 0;
if (n == 1){
$total_depth = 13.73;
$top_tilt = -14;
$top_skew = 0;
children();
} else if (n == 2) {
$total_depth = 11.73;
$top_tilt = -7;
$top_skew = 0;
children();
} else if (n == 3) {
$total_depth = 11.73;
$top_tilt = 0;
$top_skew = 0;
children();
} else if (n == 4){
$total_depth = 11.73;
$top_tilt = 7;
$top_skew = 0;
children();
}
}
module g20() {
$bottom_key_width = 18.16;
$bottom_key_height = 18.16;
$width_difference = 2;
$height_difference = 2;
$total_depth = 6;
$top_tilt = 2.5;
$top_skew = 0.75;
$dish_type = 3;
$dish_depth = 0;
$dish_skew_x = 0;
$dish_skew_y = 0;
//also,
$rounded_key = true;
}
module fake_iso_enter() {
$bottom_key_width = 18.16 * 1.5;
$bottom_key_height = 18.16 * 2;
$width_difference = 4;
$height_difference = 4;
$total_depth = 7;
$top_tilt = 0;
$top_skew = 1.75;
$dish_type = 0;
$dish_depth = 1;
$dish_skew_x = 0;
$dish_skew_y = 0;
children();
}
module brimmed() {
brim();
children();
}
module rounded() {
$rounded_key = true;
children();
}
module inverted() {
$inverted_dish = true;
children();
}
module spacebar() {
$inverted_dish = true;
$key_length = 6.25;
//TODO CONFIRM PLS
$connectors = [[0,0],[-50,0],[50,0]];
children();
}
module lshift() {
//TODO
}
module rshift() {
//TODO
}
module backspace() {
//TODO
}
module enter() {
//TODO
}
module numpad_enter() {
//TODO
}
module numpad_0() {
//TODO
}
module translate_u(x=0, y=0){
echo (x*unit);
translate([x * unit, y*unit, 0]) {
children();
}
}
// key width functions
module u(u=1) {
$key_length = u;
echo ($key_length);
children();
}
module 1u() {
u(1){
children();
}
}
module 2u() {
u(2){
children();
}
}
module 1_25u() {
u(1.25){
children();
}
}
module 1_5u() {
u(1.5){
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();
}
}
module cherry_key() {
difference() {
cherry_stem();
inside();
}
keytop();
}
module alps_key() {
difference(){
alps_stem();
inside();
}
keytop();
}
module rounded_cherry_key() {
difference(){
cherry_stem_rounded();
inside();
}
keytop();
}
for (row=[1:4]) {
for (column = [1:1]) {
translate_u(column - 1, 4 - row) dcs_row(row) alps_key();
}
}

60202
keys.scad.stl Normal file

File diff suppressed because it is too large Load Diff

88
stems.scad Normal file
View File

@ -0,0 +1,88 @@
include <variables.scad>
cross_height = 15;
module cherry_stem() {
cherry_stem_base();
}
module cherry_stem_rounded() {
// cross length
cross_length = 4.4;
//dimensions of connector
// outer cross extra length in x
extra_outer_cross_width = 2.10;
// outer cross extra length in y
extra_outer_cross_height = 1.0;
// dimensions of cross
// horizontal cross bar width
horizontal_cross_width = 1.4;
// vertical cross bar width
vertical_cross_width = 1.3;
// cross depth, stem height is 3.4mm
cross_depth = 4;
difference(){
cylinder(
d = cross_length+extra_outer_cross_height,
h = cross_height
);
//the cross part of the steam
translate([0,0,(cross_depth)/2 + stem_inset]){
cube([vertical_cross_width,cross_length,cross_depth], center=true );
cube([cross_length,horizontal_cross_width,cross_depth], center=true );
}
}
}
module cherry_stem_base(rounded = false){
// cross length
cross_length = 4.4;
//extra vertical cross length - the extra length of the up/down bar of the cross
extra_vertical_cross_length = 1.1;
//dimensions of connector
// outer cross extra length in x
extra_outer_cross_width = 2.10;
// outer cross extra length in y
extra_outer_cross_height = 1.0;
// dimensions of cross
// horizontal cross bar width
horizontal_cross_width = 1.4;
// vertical cross bar width
vertical_cross_width = 1.3;
// cross depth, stem height is 3.4mm
cross_depth = 4;
difference(){
translate([
-(cross_length+extra_outer_cross_width)/2,
-(cross_length+extra_outer_cross_height)/2,
stem_inset
]) {
cube([ // the base of the stem, the part the cruciform digs into
cross_length+extra_outer_cross_width,
cross_length+extra_outer_cross_height,
cross_height
]);
}
//the cross part of the steam
translate([0,0,(cross_depth)/2 + stem_inset]){
cube([vertical_cross_width,cross_length+extra_vertical_cross_length,cross_depth], center=true );
cube([cross_length,horizontal_cross_width,cross_depth], center=true );
}
}
}
module alps_stem(){
cross_depth = 40;
width = 4.45;
height = 2.25;
base_width = 12;
base_height = 15;
translate([0,0,cross_depth/2 + stem_inset]){
cube([width,height,cross_depth], center = true);
}
}

22
util.scad Normal file
View File

@ -0,0 +1,22 @@
//centered
module roundedRect(size, radius) {
x = size[0];
y = size[1];
z = size[2];
translate([-x/2,-y/2,0])
linear_extrude(height=z)
hull() {
translate([radius, radius, 0])
circle(r=radius);
translate([x - radius, radius, 0])
circle(r=radius);
translate([x - radius, y - radius, 0])
circle(r=radius);
translate([radius, y - radius, 0])
circle(r=radius);
}
}

0
variables.scad Normal file
View File