break out stabilizers from stems

This commit is contained in:
Robert Sheldon 2018-06-25 00:41:02 -04:00
parent 3c59a15160
commit 410f25c88e
6 changed files with 48 additions and 32 deletions

View File

@ -40,15 +40,17 @@ for (p = [0:len(key_profiles)-1]) {
/* translate_u(0, 0) one_row_profile("oem"); */ /* translate_u(0, 0) one_row_profile("oem"); */
/* dsa_row(3) u(1) uh(1) cherry() key(); */ /* dsa_row(3) u(1) uh(1) cherry() key(); */
translate_u(0) sa_row(3) cherry() { translate_u(0, 0) sa_row(3) stepped_caps_lock() {
key(); key();
} }
translate_u(1) sa_row(2) cherry() { translate_u(0, 1) sa_row(2) lshift() {
$stem_type = false;
key(); key();
} }
translate_u(2) sa_row(1) cherry() { translate_u(0, 2) sa_row(1) spacebar() alps() {
$support_type = false;
key(); key();
} }

View File

@ -173,8 +173,8 @@ module keytext(text, position, font_size, depth) {
} }
} }
module keystem_positions() { module keystem_positions(positions) {
for (connector_pos = $connectors) { for (connector_pos = positions) {
translate(connector_pos) { translate(connector_pos) {
rotate([0, 0, $stem_rotation]){ rotate([0, 0, $stem_rotation]){
children(); children();
@ -183,15 +183,15 @@ module keystem_positions() {
} }
} }
module keystems() { module support_for(positions, stem_type) {
keystem_positions() { keystem_positions(positions) {
color(color4) stem($stem_type, $total_depth, $has_brim, $stem_slop); color(color4) supports($support_type, stem_type, $stem_throw, $total_depth - $stem_throw);
} }
} }
module keystem_supports() { module stems_for(positions, stem_type) {
keystem_positions() { keystem_positions(positions) {
color(color4) supports($support_type, $stem_type, $stem_throw, $total_depth - $stem_throw); color(color4) stem(stem_type, $total_depth, $has_brim, $stem_slop);
} }
} }
@ -270,15 +270,25 @@ module key(inset = false) {
} }
// both stem and support are optional // both stem and support are optional
if ($stem_type){ if ($stem_type || $stabilizer_type) {
dished($keytop_thickness, $inverted_dish) { dished($keytop_thickness, $inverted_dish) {
translate([0, 0, $stem_inset]) keystems(); translate([0, 0, $stem_inset]) {
if ($stabilizer_type) stems_for($stabilizers, $stabilizer_type);
if ($stem_type) stems_for($stem_positions, $stem_type);
}
} }
} }
if ($support_type){ if ($support_type){
inside() { inside() {
translate([0, 0, $stem_inset]) keystem_supports(); translate([0, 0, $stem_inset]) {
if ($stabilizer_type) support_for($stabilizers, $stabilizer_type);
// always render stem support even if there isn't a stem.
// rendering flat support w/no stem is much more common than a hollow keycap
// so if you want a hollow keycap you'll have to turn support off entirely
support_for($stem_positions, $stem_type);
}
} }
} }
} }

View File

@ -28,18 +28,18 @@ module rotated() {
children(); children();
} }
module stabilized(mm=12, vertical = false) { module stabilized(mm=12, vertical = false, type="cherry") {
if (vertical) { if (vertical) {
$connectors = [ $stabilizer_type = type;
[0, 0], $stabilizers = [
[0, mm], [0, mm],
[0, -mm] [0, -mm]
]; ];
children(); children();
} else { } else {
$connectors = [ $stabilizer_type = type;
[0, 0], $stabilizers = [
[mm, 0], [mm, 0],
[-mm, 0] [-mm, 0]
]; ];

View File

@ -34,9 +34,7 @@ module numpad_0() {
module stepped_caps_lock() { module stepped_caps_lock() {
u(1.75) { u(1.75) {
$connectors = [ $stem_positions = [[-5, 0]];
[-5, 0]
];
children(); children();
} }
} }

View File

@ -45,9 +45,9 @@ $has_brim = false;
$brim_height = 0.2; $brim_height = 0.2;
// invert dishing. mostly for spacebar // invert dishing. mostly for spacebar
$inverted_dish = false; $inverted_dish = false;
// array of positions of all stems. includes stabilizers as well, for now // array of positions of stabilizers
// ternary is a bad hack to keep the stabilizers flag working // ternary is a bad hack to keep the stabilizers flag working
$connectors = $stabilizers ? [[0,0],[-50,0],[50,0]] : [[0,0]]; $stabilizers = [[-50,0],[50,0]];
// use linear_extrude instead of hull slices to make the shape of the key // use linear_extrude instead of hull slices to make the shape of the key
// should be faster, also required for concave shapes // should be faster, also required for concave shapes
$linear_extrude_shape = false; $linear_extrude_shape = false;
@ -55,6 +55,10 @@ $linear_extrude_shape = false;
$rounded_key = false; $rounded_key = false;
// what type of stem you want. To turn off stems pass false. "cherry", "alps", and "cherry_rounded" supported // what type of stem you want. To turn off stems pass false. "cherry", "alps", and "cherry_rounded" supported
$stem_type = "cherry"; $stem_type = "cherry";
// where the stems are in relation to the center of the keycap, in units. default is one in the center
$stem_positions = [[0,0]];
// what type of stem you want for the stabilizers. false disables
$stabilizer_type = false;
// how much higher the stem is than the bottom of the keycap. // how much higher the stem is than the bottom of the keycap.
// inset stem requires support but is more accurate in some profiles // inset stem requires support but is more accurate in some profiles
$stem_inset = 0; $stem_inset = 0;

View File

@ -9,14 +9,7 @@ function scale_for_45(height, starting_size) = (height * 2 + starting_size) / st
// also kind of messy... oh well // also kind of messy... oh well
module flared_support(stem_type, loft, height) { module flared_support(stem_type, loft, height) {
translate([0,0,loft]){ translate([0,0,loft]){
if(stem_type == "cherry") { if (stem_type == "cherry_rounded") {
cherry_scale = [scale_for_45(height, outer_cherry_stem()[0]), scale_for_45(height, outer_cherry_stem()[1])];
linear_extrude(height=height, scale = cherry_scale){
offset(r=1){
square(outer_cherry_stem() - [2,2], center=true);
}
}
} else if (stem_type == "cherry_rounded") {
linear_extrude(height=height, scale = scale_for_45(height, $rounded_cherry_stem_d)){ linear_extrude(height=height, scale = scale_for_45(height, $rounded_cherry_stem_d)){
circle(d=$rounded_cherry_stem_d); circle(d=$rounded_cherry_stem_d);
} }
@ -25,6 +18,15 @@ module flared_support(stem_type, loft, height) {
linear_extrude(height=height, scale = alps_scale){ linear_extrude(height=height, scale = alps_scale){
square($alps_stem, center=true); square($alps_stem, center=true);
} }
} else {
// always render cherry if no stem type. this includes stem_type = false!
// this avoids a bug where the keycap is rendered filled when not desired
cherry_scale = [scale_for_45(height, outer_cherry_stem()[0]), scale_for_45(height, outer_cherry_stem()[1])];
linear_extrude(height=height, scale = cherry_scale){
offset(r=1){
square(outer_cherry_stem() - [2,2], center=true);
}
}
} }
} }
} }