should really have a changelog huh

This commit is contained in:
Bob - Home - Windows 2017-08-13 03:04:53 -04:00
parent 44da611cdd
commit 43e20beaaa
8 changed files with 7829 additions and 71219 deletions

View File

@ -1,50 +1,64 @@
module cylindrical_dish(top_total_key_width, dish_depth, inverted_dish, top_tilt){
include <util.scad>
//rounding factor. increase rounding on dishes
$rounding_factor = 1;
module cylindrical_dish(width, height, depth, inverted, tilt){
// .5 has problems starting around 3u
$fa=.25;
/* 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 distance you have to move the dish so it digs in depth millimeters
chord_length = (pow(width, 2) - 4 * pow(depth, 2)) / (8 * 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;
rad = (pow(width, 2) + 4 * pow(depth, 2)) / (8 * depth);
direction = inverted ? -1 : 1;
rotate([90-top_tilt,0,0]){
rotate([90-tilt,0,0]){
translate([0,chord_length * direction,0]){
cylinder(h=100,r=rad, $fn=1024, center=true);
cylinder(h=height + 20, r=rad, center=true);
}
}
}
module spherical_dish(top_total_key_width, dish_depth, inverted_dish, top_tilt){
module spherical_dish(width, height, depth, inverted, tilt, txt=""){
// honestly 1 has problems around 6.25 but its already ridiculously slow
$fa=3;
//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
chord = pow((pow(width,2) + pow(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 distance you have to move the dish up so it digs in depth millimeters
chord_length = (pow(chord, 2) - 4 * pow(depth, 2)) / (8 * depth);
//the radius of the dish
rad = (pow(chord, 2) + 4 * pow(dish_depth, 2)) / (8 * dish_depth);
direction = inverted_dish ? -1 : 1;
rad = (pow(chord, 2) + 4 * pow(depth, 2)) / (8 * depth);
direction = inverted ? -1 : 1;
rotate([-top_tilt,0,0]){
/*intersection(){*/
rotate([-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);
sphere(r=rad);
}
}
// this line causes openscad to die. maybe re-enable when that doesn't happen instead of differencing the inside() when we add the dish to the shape()
/*translate([0,0,0]) roundedRect([width, height, depth], 1.5);*/
/*}*/
}
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);
module sideways_cylindrical_dish(width, height, depth, inverted, tilt){
$fa=1;
chord_length = (pow(height, 2) - 4 * pow(depth, 2)) / (8 * depth);
rad = (pow(height, 2) + 4 * pow(depth, 2)) / (8 * depth);
direction = inverted_dish ? -1 : 1;
direction = inverted ? -1 : 1;
rotate([90,top_tilt,90]){
rotate([90,tilt,90]){
translate([0,chord_length * direction,0]){
cylinder(h=total_key_width + 20,r=rad, $fn=1024, center=true); // +20 just cuz
cylinder(h = width + 20,r=rad, center=true); // +20 for fudge factor
}
}
}

161
key.scad
View File

@ -1,4 +1,3 @@
include <variables.scad>
include <util.scad>
include <stems.scad>
include <dishes.scad>
@ -15,12 +14,14 @@ brim_radius = 8;
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;
// font used for text
font="Arial";
// font size used for text
font_size = 8;
// whether or not to render fake keyswitches to check clearances
clearance_check = true;
/* [Key profile] */
@ -62,19 +63,31 @@ connectors = stabilizers ? [[0,0],[-50,0],[50,0]] : [[0,0]];
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]
stem_profile = 0;
// 'cherry', 'alps' or 'cherry_rounded'
stem_profile = "cherry";
// 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;
//text to be rendered in the center of the key, if any
text = "";
// is the text on the key inset? inset text is still experimental
inset_text = false;
/* [Hidden] */
//change to round things better
$fn = 32;
$fs = .1;
//beginning to use unit instead of baked in 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 = 1.75;
//radius of corners of keycap
corner_radius = 1.5;
// derived variables
// derived functions. can't be variables if we want them to change when the special variables do
// actual mm key width and height
function total_key_width() = $bottom_key_width + (unit * ($key_length - 1));
@ -110,12 +123,16 @@ module shape(thickness_difference, depth_difference){
shape_hull(thickness_difference, depth_difference, 1);
if ($inverted_dish) { dish(depth_difference); }
}
if (!$inverted_dish) { dish(depth_difference); }
outside(thickness_difference);
if (!$inverted_dish) {
dish(depth_difference);
} else {
// needed to trim the edges of an inverted dish
inside();
}
}
}
// shape of the key but with soft, rounded edges. much more realistic, much more complex
// shape of the key but with soft, rounded edges. much more realistic, MUCH more complex. orders of magnitude more complex
module rounded_shape() {
minkowski(){
shape(minkowski_radius*2, minkowski_radius);
@ -139,7 +156,7 @@ module shape_hull(thickness_difference, depth_difference, modifier){
// $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
// 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],corner_radius);
//depth_difference outside of modifier because that doesnt make sense
translate([0,$top_skew,$total_depth * modifier - depth_difference]){
@ -148,7 +165,7 @@ module shape_hull(thickness_difference, depth_difference, modifier){
total_key_width() - thickness_difference - $width_difference * modifier,
total_key_height() - thickness_difference - $height_difference * modifier,
.001
],1.5);
],corner_radius);
}
}
}
@ -158,39 +175,65 @@ module shape_hull(thickness_difference, depth_difference, modifier){
//dish selector
module dish(depth_difference){
translate([$dish_skew_x, $top_skew + $dish_skew_y, $total_depth - depth_difference]){
if($dish_type == 0){ // cylindrical dish
cylindrical_dish(top_total_key_width(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
if($dish_type == 0){
cylindrical_dish(top_total_key_width(), top_total_key_height(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
}
else if ($dish_type == 1) { // spherical dish
spherical_dish(top_total_key_width(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
else if ($dish_type == 1) {
spherical_dish(top_total_key_width(), top_total_key_height(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
}
else if ($dish_type == 2){ // SIDEWAYS cylindrical dish - used for spacebar
sideways_cylindrical_dish(top_total_key_width(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
else if ($dish_type == 2){
sideways_cylindrical_dish(top_total_key_width(), top_total_key_height(), $dish_depth, $inverted_dish, $top_tilt / $key_height);
}
// else no dish
}
}
//whole connector, alps or cherry, trimmed to fit
module connector(){
module keytext() {
extra_dish_depth = ($dish_type > 2) ? 0 : $dish_depth;
extra_inset_depth = ($inset_text) ? keytop_thickness/4 : 0;
translate([$dish_skew_x, $top_skew + $dish_skew_y, $total_depth - extra_dish_depth - extra_inset_depth]){
rotate([-$top_tilt,0,0]){
linear_extrude(height=$dish_depth){
text(text=$text, font=font, size=font_size, halign="center", valign="center");
}
}
}
}
module connectors($stem_profile) {
difference() {
if($stem_profile == 0) {
cherry_stem();
} else if ($stem_profile == 1) {
alps_stem();
} else if ($stem_profile == 2) {
cherry_stem_rounded();
for (connector_pos = $connectors) {
translate([connector_pos[0], connector_pos[1], $stem_inset]) {
rotate([0, 0, $stem_rotation]){
connector($stem_profile);
if ($has_brim) cylinder(r=brim_radius,h=brim_depth);
}
}
}
inside();
}
}
module brim() {
cylinder(r=brim_radius,h=brim_depth);
//approximate (fully depressed) cherry key to check clearances
module clearance_check() {
if(clearance_check == true && ($stem_profile == "cherry" || $stem_profile == "cherry_rounded")){
color([1,0,0, 0.5]){
translate([0,0,3.6 + $stem_inset - 5]) {
%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);
}
}
}
}
}
module keytop() {
echo($key_length);
difference(){
if ($rounded_key) {
rounded_shape();
@ -201,9 +244,24 @@ module keytop() {
}
}
// The final, penultimate key generation function.
// takes all the bits and glues them together. requires configuration with special variables.
module key() {
difference() {
union(){
keytop();
if($stem_profile != "blank") connectors($stem_profile);
if(!$inset_text) keytext();
clearance_check();
}
if ($inset_text) keytext();
}
}
// actual full key with space carved out and keystem/stabilizer connectors
// this is an example key with all the fixins
module key(){
module example_key(){
$bottom_key_width = bottom_key_width;
$bottom_key_height = bottom_key_height;
$width_difference = width_difference;
@ -223,32 +281,31 @@ module key(){
$ISOEnter = ISOEnter;
$rounded_key = rounded_key;
$stem_profile = stem_profile;
$stem_inset = stem_inset;
$stem_rotation = stem_rotation;
$text = text;
$inset_text = inset_text;
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();
}
}
// ACTUAL OUTPUT
difference(){
key();
// preview cube, for seeing inside the keycap
//cube([100,100,100]);
}
example_key();
//minkowski_key();
// Experimental stuff
// NOT 3D, NOT CENTERED

18384
key.scad.stl

File diff suppressed because it is too large Load Diff

BIN
key_v2.zip Normal file

Binary file not shown.

205
keys.scad
View File

@ -1,3 +1,12 @@
/* TODO:
* can now measure keycaps very accurately. need to redo measurements
* sideways cylindrical dish needs to be used for some spacebars but not others. currently none of them use it
* Add inset stem to all profiles that need it
* Pregenerated keysets
* Full experimental ISO enter
* customizer version where everything is copy/pasted in
*/
use <key.scad>
//TODO duplicate def to not make this a special var. maybe not worth it
unit = 19.05;
@ -22,46 +31,42 @@ $connectors = [[0,0]];
$ISOEnter = false;
$rounded_key = false;
$stem_profile = 0;
$stem_inset = 0;
$stem_rotation = 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_type = 2;
$dish_depth = 1;
$dish_skew_x = 0;
$dish_skew_y = 0;
$top_skew = 1.75;
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();
}
}
@ -72,7 +77,7 @@ module dsa_row(n=3) {
$width_difference = 5.7;
$height_difference = 5.7;
$total_depth = 7.4;
$top_tilt = 0;
$top_tilt = (n-1) * 7 - 14;
$top_skew = 0;
$dish_type = 1;
$dish_depth = 1.2;
@ -88,29 +93,26 @@ module sa_row(n=1) {
$width_difference = 5.7;
$height_difference = 5.7;
$dish_type = 1;
$dish_depth = 1.2;
$dish_depth = 0.85;
$dish_skew_x = 0;
$dish_skew_y = 0;
$top_skew = 0;
if (n == 1){
$total_depth = 13.73;
$top_tilt = -14;
$top_skew = 0;
$total_depth = 14.89;
$top_tilt = -13;
children();
} else if (n == 2) {
$total_depth = 11.73;
$total_depth = 12.925;
$top_tilt = -7;
$top_skew = 0;
children();
} else if (n == 3) {
$total_depth = 11.73;
$total_depth = 12.5;
$top_tilt = 0;
$top_skew = 0;
children();
} else if (n == 4){
$total_depth = 11.73;
$total_depth = 12.925;
$top_tilt = 7;
$top_skew = 0;
children();
}
}
@ -149,7 +151,7 @@ module fake_iso_enter() {
}
module brimmed() {
brim();
$has_brim = true;
children();
}
@ -163,93 +165,111 @@ module inverted() {
children();
}
module stabilized(mm=12, vertical = false) {
if (vertical) {
$connectors = [
[0, 0],
[0, mm],
[0, -mm]
];
children();
} else {
$connectors = [
[0, 0],
[mm, 0],
[-mm, 0]
];
children();
}
}
module dishless() {
$dish_type = 3;
children();
}
module spacebar() {
$inverted_dish = true;
$key_length = 6.25;
//TODO CONFIRM PLS
$connectors = [[0,0],[-50,0],[50,0]];
children();
6_25u() stabilized(mm=50) children();
}
module lshift() {
//TODO
2_25u() stabilized() children();
}
module rshift() {
//TODO
2_75u() stabilized() children();
}
module backspace() {
//TODO
2u() stabilized() children();
}
module enter() {
//TODO
2_25u() stabilized() children();
}
module numpad_enter() {
//TODO
2uh() stabilized(vertical=true) children();
}
module numpad_plus() {
numpad_enter() children();
}
module numpad_0() {
//TODO
backspace() children();
}
module translate_u(x=0, y=0){
echo (x*unit);
translate([x * unit, y*unit, 0]) {
module stepped_caps_lock() {
u(1.75) {
$connectors = [
[-5, 0]
];
children();
}
}
module translate_u(x=0, y=0, z=0){
translate([x * unit, y*unit, z*unit]) children();
}
// key width functions
module u(u=1) {
$key_length = u;
echo ($key_length);
children();
}
module 1u() {
u(1){
children();
}
u(1) children();
}
module 2u() {
u(2){
children();
}
}
module 1_25u() {
u(1.25){
children();
}
u(1.25) children();
}
module 1_5u() {
u(1.5){
children();
u(1.5) children();
}
module 2u() {
u(2) children();
}
module 2_25u() {
u(2.25){
children();
}
u(2.25) children();
}
module 2_75u() {
u(2.75){
children();
}
u(2.75) children();
}
module 6_25u() {
u(6.25){
children();
}
u(6.25) children();
}
// key height functions
@ -260,76 +280,63 @@ module uh(u=1) {
}
module 1uh() {
uh(1){
children();
}
uh(1) children();
}
module 2uh() {
uh(2){
children();
}
uh(2) children();
}
module 1_25uh() {
uh(1.25){
children();
}
uh(1.25) children();
}
module 1_5uh() {
uh(1.5){
children();
}
uh(1.5) children();
}
module 2_25uh() {
uh(2.25){
children();
}
uh(2.25) children();
}
module 2_75uh() {
uh(2.75){
children();
}
uh(2.75) children();
}
module 6_25uh() {
uh(6.25){
uh(6.25) children();
}
module blank() {
$stem_profile = "blank";
children();
}
module cherry() {
$stem_profile = "cherry";
children();
}
module cherry_key() {
difference() {
cherry_stem();
inside();
module alps() {
$stem_profile = "alps";
children();
}
keytop();
module rounded_cherry() {
$stem_profile = "cherry_rounded";
children();
}
module alps_key() {
difference(){
alps_stem();
inside();
module legend(text, inset=false) {
$text=text;
$inset_text = inset;
}
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();
translate([0,0,0]){
for (x = [1:4]){
translate_u(0,(x-1)){
sa_row(5-x) blank() key();
}
}
translate([-10,-10,-2]) cube([40,80,2]);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,4 @@
include <variables.scad>
cross_height = 15;
cross_height = 25;
module cherry_stem() {
cherry_stem_base();
@ -86,3 +84,15 @@ module alps_stem(){
cube([width,height,cross_depth], center = true);
}
}
//whole connector, alps or cherry, trimmed to fit
module connector(stem_profile){
if (stem_profile == "alps") {
alps_stem();
} else if (stem_profile == "cherry_rounded") {
cherry_stem_rounded();
} else if (stem_profile == "cherry") {
cherry_stem();
}
}

View File