autolegends

doesn't work yet, because you can't fit an arbitrary object into a
bounding box while maintaining aspect ratio
This commit is contained in:
Bob 2022-02-21 15:52:16 -05:00
parent 1a10d1e5bc
commit e955331e8d
7 changed files with 139 additions and 6 deletions

View File

@ -162,12 +162,14 @@ $double_sculpted = false;
//valign = "top" or "center" or "bottom" //valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it // Currently does not work with thingiverse customizer, and actually breaks it
$legends = []; $legends = [];
$autolegends = [];
//list of front legends to place on a key format: [text, halign, valign, size] //list of front legends to place on a key format: [text, halign, valign, size]
//halign = "left" or "center" or "right" //halign = "left" or "center" or "right"
//valign = "top" or "center" or "bottom" //valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it // Currently does not work with thingiverse customizer, and actually breaks it
$front_legends = []; $front_legends = [];
$front_autolegends = [];
// print legends on the front of the key instead of the top // print legends on the front of the key instead of the top
$front_print_legends = false; $front_print_legends = false;
@ -175,6 +177,9 @@ $front_print_legends = false;
// how recessed inset legends / artisans are from the top of the key // how recessed inset legends / artisans are from the top of the key
$inset_legend_depth = 0.2; $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 // Dimensions of alps stem
$alps_stem = [4.45, 2.25]; $alps_stem = [4.45, 2.25];
@ -1105,6 +1110,18 @@ module front_legend(text, position=[0,0], size=undef) {
children(); 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) { module bump(depth=undef) {
$key_bump = true; $key_bump = true;
$key_bump_depth = depth == undef ? $key_bump_depth : depth; $key_bump_depth = depth == undef ? $key_bump_depth : depth;
@ -5034,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 // use skin() instead of successive hulls. much more correct, and looks faster
// too, in most cases. successive hull relies on overlapping faces which are // 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 // not good. But, skin works on vertex sets instead of shapes, which makes it
@ -6242,7 +6298,10 @@ module additive_features(inset) {
if($key_bump) keybump($key_bump_depth, $key_bump_edge); if($key_bump) keybump($key_bump_depth, $key_bump_edge);
if(!inset && $children > 0) color($secondary_color) children(); 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 // render the clearance check if it's enabled, but don't have it intersect with anything
if ($clearance_check) %clearance_check(); if ($clearance_check) %clearance_check();
} }
@ -6252,7 +6311,10 @@ module subtractive_features(inset) {
top_of_key() { top_of_key() {
if (inset && $children > 0) color($secondary_color) children(); 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 // subtract the clearance check if it's enabled, letting the user see the
// parts of the keycap that will hit the cherry switch // parts of the keycap that will hit the cherry switch
// this is a little confusing as it eats the stem too // this is a little confusing as it eats the stem too
@ -6468,12 +6530,14 @@ $double_sculpted = false;
//valign = "top" or "center" or "bottom" //valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it // Currently does not work with thingiverse customizer, and actually breaks it
$legends = []; $legends = [];
$autolegends = [];
//list of front legends to place on a key format: [text, halign, valign, size] //list of front legends to place on a key format: [text, halign, valign, size]
//halign = "left" or "center" or "right" //halign = "left" or "center" or "right"
//valign = "top" or "center" or "bottom" //valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it // Currently does not work with thingiverse customizer, and actually breaks it
$front_legends = []; $front_legends = [];
$front_autolegends = [];
// print legends on the front of the key instead of the top // print legends on the front of the key instead of the top
$front_print_legends = false; $front_print_legends = false;
@ -6481,6 +6545,9 @@ $front_print_legends = false;
// how recessed inset legends / artisans are from the top of the key // how recessed inset legends / artisans are from the top of the key
$inset_legend_depth = 0.2; $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 // Dimensions of alps stem
$alps_stem = [4.45, 2.25]; $alps_stem = [4.45, 2.25];

View File

@ -9,8 +9,11 @@ include <./includes.scad>
// example key // 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 // example row
/* for (x = [0:1:4]) { /* for (x = [0:1:4]) {
translate_u(0,-x) dcs_row(x) key(); translate_u(0,-x) dcs_row(x) key();

View File

@ -3,3 +3,4 @@
include <features/key_bump.scad> include <features/key_bump.scad>
include <features/clearance_check.scad> include <features/clearance_check.scad>
include <features/legends.scad> include <features/legends.scad>
include <features/autolegends.scad>

View 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");
}
// }
}
}
}
}
}
}
}
}

View File

@ -180,7 +180,10 @@ module additive_features(inset) {
if($key_bump) keybump($key_bump_depth, $key_bump_edge); if($key_bump) keybump($key_bump_depth, $key_bump_edge);
if(!inset && $children > 0) color($secondary_color) children(); 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 // render the clearance check if it's enabled, but don't have it intersect with anything
if ($clearance_check) %clearance_check(); if ($clearance_check) %clearance_check();
} }
@ -190,7 +193,10 @@ module subtractive_features(inset) {
top_of_key() { top_of_key() {
if (inset && $children > 0) color($secondary_color) children(); 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 // subtract the clearance check if it's enabled, letting the user see the
// parts of the keycap that will hit the cherry switch // parts of the keycap that will hit the cherry switch
// this is a little confusing as it eats the stem too // this is a little confusing as it eats the stem too

View File

@ -170,6 +170,18 @@ module front_legend(text, position=[0,0], size=undef) {
children(); 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) { module bump(depth=undef) {
$key_bump = true; $key_bump = true;
$key_bump_depth = depth == undef ? $key_bump_depth : depth; $key_bump_depth = depth == undef ? $key_bump_depth : depth;

View File

@ -147,12 +147,14 @@ $double_sculpted = false;
//valign = "top" or "center" or "bottom" //valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it // Currently does not work with thingiverse customizer, and actually breaks it
$legends = []; $legends = [];
$autolegends = [];
//list of front legends to place on a key format: [text, halign, valign, size] //list of front legends to place on a key format: [text, halign, valign, size]
//halign = "left" or "center" or "right" //halign = "left" or "center" or "right"
//valign = "top" or "center" or "bottom" //valign = "top" or "center" or "bottom"
// Currently does not work with thingiverse customizer, and actually breaks it // Currently does not work with thingiverse customizer, and actually breaks it
$front_legends = []; $front_legends = [];
$front_autolegends = [];
// print legends on the front of the key instead of the top // print legends on the front of the key instead of the top
$front_print_legends = false; $front_print_legends = false;
@ -160,6 +162,9 @@ $front_print_legends = false;
// how recessed inset legends / artisans are from the top of the key // how recessed inset legends / artisans are from the top of the key
$inset_legend_depth = 0.2; $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 // Dimensions of alps stem
$alps_stem = [4.45, 2.25]; $alps_stem = [4.45, 2.25];