mirror of
https://github.com/rsheldiii/KeyV2.git
synced 2026-01-14 22:37:56 -05:00
Compare commits
1 Commits
v2/resin
...
v2/autoleg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e955331e8d |
@@ -162,12 +162,14 @@ $double_sculpted = false;
|
||||
//valign = "top" or "center" or "bottom"
|
||||
// Currently does not work with thingiverse customizer, and actually breaks it
|
||||
$legends = [];
|
||||
$autolegends = [];
|
||||
|
||||
//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 = [];
|
||||
$front_autolegends = [];
|
||||
|
||||
// print legends on the front of the key instead of the top
|
||||
$front_print_legends = false;
|
||||
@@ -175,6 +177,9 @@ $front_print_legends = false;
|
||||
// how recessed inset legends / artisans are from the top of the key
|
||||
$inset_legend_depth = 0.2;
|
||||
|
||||
// legends are not allowed to print within this many mm of the edge of the key
|
||||
$legend_margin = 0.8;
|
||||
|
||||
// Dimensions of alps stem
|
||||
$alps_stem = [4.45, 2.25];
|
||||
|
||||
@@ -1105,6 +1110,18 @@ module front_legend(text, position=[0,0], size=undef) {
|
||||
children();
|
||||
}
|
||||
|
||||
module autolegend(texts) {
|
||||
// $autolegends = [for(L=[$legends, [[text, position, font_size]]], a=L) a];
|
||||
$autolegends = texts;
|
||||
children();
|
||||
}
|
||||
|
||||
module front_autolegend(texts) {
|
||||
font_size = size == undef ? $font_size : size;
|
||||
$front_autolegends = [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;
|
||||
@@ -1130,7 +1147,7 @@ module upside_down() {
|
||||
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); // TODO assumes centered top
|
||||
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();
|
||||
}
|
||||
@@ -1158,14 +1175,7 @@ module auto_place() {
|
||||
translate_u(x,-y) children(child_index);
|
||||
}
|
||||
}
|
||||
|
||||
// suggested settings for resin prints
|
||||
module resin() {
|
||||
$stem_slop = 0;
|
||||
$stem_inner_slop = 0;
|
||||
$stem_support_type = "disable";
|
||||
children();
|
||||
}module arrows(profile, rows = [4,4,4,3]) {
|
||||
module arrows(profile, rows = [4,4,4,3]) {
|
||||
positions = [[0, 0], [1, 0], [2, 0], [1, 1]];
|
||||
legends = ["←", "↓", "→", "↑"];
|
||||
|
||||
@@ -3315,7 +3325,7 @@ function unit_length(length) = $unit * (length - 1) + 18.16;
|
||||
|
||||
// extra length to the vertical tine of the inside cherry cross
|
||||
// splits the stem into halves - allows easier fitment
|
||||
extra_vertical = 100;
|
||||
extra_vertical = 0.6;
|
||||
|
||||
module inside_cherry_cross(slop) {
|
||||
// inside cross
|
||||
@@ -3501,7 +3511,7 @@ function unit_length(length) = $unit * (length - 1) + 18.16;
|
||||
|
||||
// extra length to the vertical tine of the inside cherry cross
|
||||
// splits the stem into halves - allows easier fitment
|
||||
extra_vertical = 100;
|
||||
extra_vertical = 0.6;
|
||||
|
||||
module inside_cherry_cross(slop) {
|
||||
// inside cross
|
||||
@@ -3697,7 +3707,7 @@ function unit_length(length) = $unit * (length - 1) + 18.16;
|
||||
|
||||
// extra length to the vertical tine of the inside cherry cross
|
||||
// splits the stem into halves - allows easier fitment
|
||||
extra_vertical = 100;
|
||||
extra_vertical = 0.6;
|
||||
|
||||
module inside_cherry_cross(slop) {
|
||||
// inside cross
|
||||
@@ -4056,7 +4066,7 @@ function unit_length(length) = $unit * (length - 1) + 18.16;
|
||||
|
||||
// extra length to the vertical tine of the inside cherry cross
|
||||
// splits the stem into halves - allows easier fitment
|
||||
extra_vertical = 100;
|
||||
extra_vertical = 0.6;
|
||||
|
||||
module inside_cherry_cross(slop) {
|
||||
// inside cross
|
||||
@@ -4299,7 +4309,7 @@ function unit_length(length) = $unit * (length - 1) + 18.16;
|
||||
|
||||
// extra length to the vertical tine of the inside cherry cross
|
||||
// splits the stem into halves - allows easier fitment
|
||||
extra_vertical = 100;
|
||||
extra_vertical = 0.6;
|
||||
|
||||
module inside_cherry_cross(slop) {
|
||||
// inside cross
|
||||
@@ -4368,7 +4378,7 @@ module tines_support(stem_type, stem_support_height, slop) {
|
||||
}
|
||||
|
||||
// 2 vertical tines holding either side of the cruciform
|
||||
for (x = [2, -2]) {
|
||||
for (x = [1.15, -1.15]) {
|
||||
translate([x,0,$stem_support_height / 2]) {
|
||||
cube([
|
||||
0.5,
|
||||
@@ -5041,6 +5051,45 @@ module legends(depth=0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
module autolegends(depth=0) {
|
||||
if (len($front_autolegends) > 0) {
|
||||
front_of_key() {
|
||||
for (i=[0:len($front_legends)-1]) {
|
||||
rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (len($autolegends) > 0) {
|
||||
// legends are printed in a square grid - 1, 4, 9 legends, etc
|
||||
grid_size = len($autolegends)^0.5;
|
||||
echo("grid_size", grid_size);
|
||||
max_width = (top_total_key_width() - $legend_margin * (grid_size + 1)) / grid_size;
|
||||
max_height = (top_total_key_height() - $legend_margin * (grid_size + 1)) / grid_size;
|
||||
|
||||
top_of_key() {
|
||||
for (column=[0:grid_size-1]) {
|
||||
for (row=[0:grid_size-1]) {
|
||||
top_left_corner = [-top_total_key_width()/2, top_total_key_height()/2];
|
||||
centering_offset = [max_width / 2, -max_height / 2];
|
||||
position_offset = [(max_width + $legend_margin) * column, (-max_height-$legend_margin) * row];
|
||||
margin_offset = [$legend_margin, -$legend_margin];
|
||||
|
||||
translate(top_left_corner + centering_offset + position_offset + margin_offset) {
|
||||
translate([0,0,-depth]) {
|
||||
color($tertiary_color) linear_extrude(height=$dish_depth + depth){
|
||||
// resize([0, max_height, 0]) {
|
||||
resize([max_width, 0], auto=true) {
|
||||
text(text=$autolegends[row * grid_size + column], font=$font, halign="center", valign="center");
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// use skin() instead of successive hulls. much more correct, and looks faster
|
||||
// too, in most cases. successive hull relies on overlapping faces which are
|
||||
// not good. But, skin works on vertex sets instead of shapes, which makes it
|
||||
@@ -6249,7 +6298,10 @@ module additive_features(inset) {
|
||||
if($key_bump) keybump($key_bump_depth, $key_bump_edge);
|
||||
if(!inset && $children > 0) color($secondary_color) children();
|
||||
}
|
||||
if($outset_legends) legends(0);
|
||||
if($outset_legends) {
|
||||
legends(0);
|
||||
autolegends(0);
|
||||
}
|
||||
// render the clearance check if it's enabled, but don't have it intersect with anything
|
||||
if ($clearance_check) %clearance_check();
|
||||
}
|
||||
@@ -6259,7 +6311,10 @@ module subtractive_features(inset) {
|
||||
top_of_key() {
|
||||
if (inset && $children > 0) color($secondary_color) children();
|
||||
}
|
||||
if(!$outset_legends) legends($inset_legend_depth);
|
||||
if(!$outset_legends) {
|
||||
legends($inset_legend_depth);
|
||||
autolegends($inset_legend_depth);
|
||||
}
|
||||
// subtract the clearance check if it's enabled, letting the user see the
|
||||
// parts of the keycap that will hit the cherry switch
|
||||
// this is a little confusing as it eats the stem too
|
||||
@@ -6475,12 +6530,14 @@ $double_sculpted = false;
|
||||
//valign = "top" or "center" or "bottom"
|
||||
// Currently does not work with thingiverse customizer, and actually breaks it
|
||||
$legends = [];
|
||||
$autolegends = [];
|
||||
|
||||
//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 = [];
|
||||
$front_autolegends = [];
|
||||
|
||||
// print legends on the front of the key instead of the top
|
||||
$front_print_legends = false;
|
||||
@@ -6488,6 +6545,9 @@ $front_print_legends = false;
|
||||
// how recessed inset legends / artisans are from the top of the key
|
||||
$inset_legend_depth = 0.2;
|
||||
|
||||
// legends are not allowed to print within this many mm of the edge of the key
|
||||
$legend_margin = 0.8;
|
||||
|
||||
// Dimensions of alps stem
|
||||
$alps_stem = [4.45, 2.25];
|
||||
|
||||
|
||||
@@ -9,8 +9,11 @@ include <./includes.scad>
|
||||
|
||||
|
||||
// example key
|
||||
dcs_row(5) legend("⇪", size=9) key();
|
||||
|
||||
$stem_inner_slop = 0;
|
||||
dcs_row(5) autolegend(["q", "w", "a", "z", "e", "r", "t", "", "hoobastank"]) {
|
||||
$stem_positions = [[2,2]];
|
||||
key();
|
||||
}
|
||||
// example row
|
||||
/* for (x = [0:1:4]) {
|
||||
translate_u(0,-x) dcs_row(x) key();
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
include <features/key_bump.scad>
|
||||
include <features/clearance_check.scad>
|
||||
include <features/legends.scad>
|
||||
include <features/autolegends.scad>
|
||||
|
||||
39
src/features/autolegends.scad
Normal file
39
src/features/autolegends.scad
Normal file
@@ -0,0 +1,39 @@
|
||||
module autolegends(depth=0) {
|
||||
if (len($front_autolegends) > 0) {
|
||||
front_of_key() {
|
||||
for (i=[0:len($front_legends)-1]) {
|
||||
rotate([90,0,0]) keytext($front_legends[i][0], $front_legends[i][1], $front_legends[i][2], depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (len($autolegends) > 0) {
|
||||
// legends are printed in a square grid - 1, 4, 9 legends, etc
|
||||
grid_size = len($autolegends)^0.5;
|
||||
echo("grid_size", grid_size);
|
||||
max_width = (top_total_key_width() - $legend_margin * (grid_size + 1)) / grid_size;
|
||||
max_height = (top_total_key_height() - $legend_margin * (grid_size + 1)) / grid_size;
|
||||
|
||||
top_of_key() {
|
||||
for (column=[0:grid_size-1]) {
|
||||
for (row=[0:grid_size-1]) {
|
||||
top_left_corner = [-top_total_key_width()/2, top_total_key_height()/2];
|
||||
centering_offset = [max_width / 2, -max_height / 2];
|
||||
position_offset = [(max_width + $legend_margin) * column, (-max_height-$legend_margin) * row];
|
||||
margin_offset = [$legend_margin, -$legend_margin];
|
||||
|
||||
translate(top_left_corner + centering_offset + position_offset + margin_offset) {
|
||||
translate([0,0,-depth]) {
|
||||
color($tertiary_color) linear_extrude(height=$dish_depth + depth){
|
||||
// resize([0, max_height, 0]) {
|
||||
resize([max_width, 0], auto=true) {
|
||||
text(text=$autolegends[row * grid_size + column], font=$font, halign="center", valign="center");
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/key.scad
10
src/key.scad
@@ -180,7 +180,10 @@ module additive_features(inset) {
|
||||
if($key_bump) keybump($key_bump_depth, $key_bump_edge);
|
||||
if(!inset && $children > 0) color($secondary_color) children();
|
||||
}
|
||||
if($outset_legends) legends(0);
|
||||
if($outset_legends) {
|
||||
legends(0);
|
||||
autolegends(0);
|
||||
}
|
||||
// render the clearance check if it's enabled, but don't have it intersect with anything
|
||||
if ($clearance_check) %clearance_check();
|
||||
}
|
||||
@@ -190,7 +193,10 @@ module subtractive_features(inset) {
|
||||
top_of_key() {
|
||||
if (inset && $children > 0) color($secondary_color) children();
|
||||
}
|
||||
if(!$outset_legends) legends($inset_legend_depth);
|
||||
if(!$outset_legends) {
|
||||
legends($inset_legend_depth);
|
||||
autolegends($inset_legend_depth);
|
||||
}
|
||||
// subtract the clearance check if it's enabled, letting the user see the
|
||||
// parts of the keycap that will hit the cherry switch
|
||||
// this is a little confusing as it eats the stem too
|
||||
|
||||
@@ -170,6 +170,18 @@ module front_legend(text, position=[0,0], size=undef) {
|
||||
children();
|
||||
}
|
||||
|
||||
module autolegend(texts) {
|
||||
// $autolegends = [for(L=[$legends, [[text, position, font_size]]], a=L) a];
|
||||
$autolegends = texts;
|
||||
children();
|
||||
}
|
||||
|
||||
module front_autolegend(texts) {
|
||||
font_size = size == undef ? $font_size : size;
|
||||
$front_autolegends = [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;
|
||||
@@ -195,7 +207,7 @@ module upside_down() {
|
||||
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); // TODO assumes centered top
|
||||
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();
|
||||
}
|
||||
@@ -223,11 +235,3 @@ module auto_place() {
|
||||
translate_u(x,-y) children(child_index);
|
||||
}
|
||||
}
|
||||
|
||||
// suggested settings for resin prints
|
||||
module resin() {
|
||||
$stem_slop = 0;
|
||||
$stem_inner_slop = 0;
|
||||
$stem_support_type = "disable";
|
||||
children();
|
||||
}
|
||||
@@ -147,12 +147,14 @@ $double_sculpted = false;
|
||||
//valign = "top" or "center" or "bottom"
|
||||
// Currently does not work with thingiverse customizer, and actually breaks it
|
||||
$legends = [];
|
||||
$autolegends = [];
|
||||
|
||||
//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 = [];
|
||||
$front_autolegends = [];
|
||||
|
||||
// print legends on the front of the key instead of the top
|
||||
$front_print_legends = false;
|
||||
@@ -160,6 +162,9 @@ $front_print_legends = false;
|
||||
// how recessed inset legends / artisans are from the top of the key
|
||||
$inset_legend_depth = 0.2;
|
||||
|
||||
// legends are not allowed to print within this many mm of the edge of the key
|
||||
$legend_margin = 0.8;
|
||||
|
||||
// Dimensions of alps stem
|
||||
$alps_stem = [4.45, 2.25];
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ module tines_support(stem_type, stem_support_height, slop) {
|
||||
}
|
||||
|
||||
// 2 vertical tines holding either side of the cruciform
|
||||
for (x = [2, -2]) {
|
||||
for (x = [1.15, -1.15]) {
|
||||
translate([x,0,$stem_support_height / 2]) {
|
||||
cube([
|
||||
0.5,
|
||||
|
||||
@@ -2,7 +2,7 @@ include <../functions.scad>
|
||||
|
||||
// extra length to the vertical tine of the inside cherry cross
|
||||
// splits the stem into halves - allows easier fitment
|
||||
extra_vertical = 100;
|
||||
extra_vertical = 0.6;
|
||||
|
||||
module inside_cherry_cross(slop) {
|
||||
// inside cross
|
||||
|
||||
Reference in New Issue
Block a user