Merge branch 'v2.0.0' into key-features

This commit is contained in:
Bob 2020-05-12 16:43:50 -04:00 committed by GitHub
commit b29a5f3c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 220 additions and 66 deletions

View File

@ -60,7 +60,7 @@ You can chain as many modifier functions as you like!
## Modifier functions
There is a bevy of supporting functions to customize your keycaps. You can add a brim to more easily print the stem with `brimmed_stem_support`, make 2x2 keycaps with `2u() 2uh()`, add legends, rotate stems, and more. All these functions manipulate the settings available to you in [`settings.scad`](https://github.com/rsheldiii/KeyV2/blob/master/src/settings.scad), though [some of them](https://github.com/rsheldiii/KeyV2/blob/master/src/key_transformations.scad#L128) are quite complex.
There is a bevy of supporting functions to customize your keycaps. You can add a brim to more easily print the stem with `brimmed_stem_support`, make 2x2 keycaps with `2u() 2uh()`, add legends, rotate stems, and more. All these functions manipulate the settings available to you in [`settings.scad`](https://github.com/rsheldiii/KeyV2/blob/master/src/settings.scad), though [some of them](https://github.com/rsheldiii/KeyV2/blob/851ececdb297c77bfbcd0a7cb4cdbc5e21970396/src/key_transformations.scad#L128) are quite complex.
These modifier functions can be found in [`key_profiles/`](https://github.com/rsheldiii/KeyV2/blob/master/src/key_profiles) for different keycap profiles, [`key_types.scad`](https://github.com/rsheldiii/KeyV2/blob/master/src/key_types.scad) for predefined settings for common keys (spacebar, left shift, etc), [`key_sizes.scad`](https://github.com/rsheldiii/KeyV2/blob/master/src/key_sizes.scad) for common unit sizes, and [`key_transformations.scad`](https://github.com/rsheldiii/KeyV2/blob/master/src/key_transformations.scad) for everything else. I encourage you to do some sleuthing but for a list of (most) helper functions with explanations, [Check out the wiki!](https://github.com/rsheldiii/KeyV2/wiki/KeyV2-Helper-Documentation)

View File

@ -52,7 +52,7 @@ $outset_legends = false;
// Height in units of key. should remain 1 for most uses
$key_height = 1.0;
// Keytop thickness, aka how many millimeters between the inside and outside of the top surface of the key
$keytop_thickness = 1;
$keytop_thickness = 2;
// 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;
// Radius of corners of keycap
@ -101,7 +101,7 @@ $extra_long_stem_support = false;
// Key shape type, determines the shape of the key. default is 'rounded square'
$key_shape_type = "rounded_square";
// ISO enter needs to be linear extruded NOT from the center. this tells the program how far up 'not from the center' is
// ISO enter needs to be linear extruded NOT from the center when not using skin. this tells the program how far up 'not from the center' is
$linear_extrude_height_adjustment = 0;
// How many slices will be made, to approximate curves on corners. Leave at 1 if you are not curving corners
// If you're doing fancy bowed keycap sides, this controls how many slices you take
@ -199,6 +199,19 @@ $tertiary_color = [1, .6941, .2];
$quaternary_color = [.4078, .3569, .749];
$warning_color = [1,0,0, 0.15];
// 3d surface variables
// see functions.scad for the surface function
$3d_surface_size = 10;
$3d_surface_step = 1;
// normally the bottom of the keytop looks like the top - curved, at least
// underneath the support structure. This ensures there's a minimum thickness for the
// underside of the keycap, but it's a fair bit of geometry
$flat_keytop_bottom = true;
// how many facets circles will have when used in these features
$minkowski_facets = 30;
$shape_facets =30;
// key width functions
module u(u=1) {
@ -970,17 +983,9 @@ function iso_enter_vertices(width, height, width_ratio, height_ratio, wd, hd) =
// no rounding on the corners at all
function skin_iso_enter_shape(size, delta, progress, thickness_difference) =
iso_enter_vertices(size.x, size.y, unit_length(1.25) / unit_length(1.5), unit_length(1) / unit_length(2), thickness_difference/2 + delta.x * progress/2, thickness_difference/2 + delta.y * progress/2);
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, fn) * [size[0]/2-r,0]
+ sign_y(index, fn) * [0,size[1]/2-r]
];
function sign_x(i,n) =
i < n/4 || i > n-n/4 ? 1 :
i > n/4 && i < n-n/4 ? -1 :
i < n/4 || i > n*3/4 ? 1 :
i > n/4 && i < n*3/4 ? -1 :
0;
function sign_y(i,n) =
@ -988,6 +993,32 @@ function sign_y(i,n) =
i > n/2 ? -1 :
0;
function rectangle_profile(size=[1,1],fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
sign_x(index, fn) * [size[0]/2,0]
+ sign_y(index, fn) * [0,size[1]/2]
];
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];
function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];
// rounded square shape with additional sculpting functions to better approximate
// When sculpting sides, how much in should the tops come
@ -1025,7 +1056,7 @@ module sculpted_square_shape(size, delta, progress) {
height - extra_height_this_slice
];
offset(r = extra_corner_radius_this_slice) {
offset(r = extra_corner_radius_this_slice, $fa=360/$shape_facets) {
offset(r = -extra_corner_radius_this_slice) {
side_rounded_square(square_size, r = $more_side_sculpting_factor * progress);
}
@ -1034,7 +1065,7 @@ module sculpted_square_shape(size, delta, progress) {
// fudging the hell out of this, I don't remember what the negative-offset-positive-offset was doing in the module above
// also no 'bowed' square shape for now
function skin_sculpted_square_shape(size, delta, progress) =
function skin_sculpted_square_shape(size, delta, progress, thickness_difference) =
let(
width = size[0],
height = size[1],
@ -1052,10 +1083,10 @@ function skin_sculpted_square_shape(size, delta, progress) =
extra_corner_radius_this_slice = ($corner_radius + extra_corner_size),
square_size = [
width - extra_width_this_slice,
height - extra_height_this_slice
width - extra_width_this_slice - thickness_difference,
height - extra_height_this_slice - thickness_difference
]
) rounded_rectangle_profile(square_size - [extra_corner_radius_this_slice, extra_corner_radius_this_slice]/4, fn=36, r=extra_corner_radius_this_slice/1.5 + $more_side_sculpting_factor * progress);
) double_rounded_rectangle_profile(square_size - [extra_corner_radius_this_slice, extra_corner_radius_this_slice]/4, fn=$shape_facets, r=extra_corner_radius_this_slice/1.5 + $more_side_sculpting_factor * progress);
/* offset(r = extra_corner_radius_this_slice) {
offset(r = -extra_corner_radius_this_slice) {
@ -1073,25 +1104,17 @@ module side_rounded_square(size, r) {
sw = iw / resolution;
union() {
if (sr > 0) {
translate([-iw/2, 0]) scale([sr, sh]) circle(d = resolution);
translate([iw/2, 0]) scale([sr, sh]) circle(d = resolution);
translate([0, -ih/2]) scale([sw, sr]) circle(d = resolution);
translate([0, ih/2]) scale([sw, sr]) circle(d = resolution);
translate([-iw/2, 0]) scale([sr, sh]) circle(d = resolution, $fa=360/$shape_facets);
translate([iw/2, 0]) scale([sr, sh]) circle(d = resolution, $fa=360/$shape_facets);
translate([0, -ih/2]) scale([sw, sr]) circle(d = resolution, $fa=360/$shape_facets);
translate([0, ih/2]) scale([sw, sr]) circle(d = resolution, $fa=360/$shape_facets);
}
square([iw, ih], center=true);
}
}
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, fn) * [size[0]/2-r,0]
+ sign_y(index, fn) * [0,size[1]/2-r]
];
function sign_x(i,n) =
i < n/4 || i > n-n/4 ? 1 :
i > n/4 && i < n-n/4 ? -1 :
i < n/4 || i > n*3/4 ? 1 :
i > n/4 && i < n*3/4 ? -1 :
0;
function sign_y(i,n) =
@ -1099,16 +1122,42 @@ function sign_y(i,n) =
i > n/2 ? -1 :
0;
function rectangle_profile(size=[1,1],fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
sign_x(index, fn) * [size[0]/2,0]
+ sign_y(index, fn) * [0,size[1]/2]
];
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];
function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];
module rounded_square_shape(size, delta, progress, center = true) {
offset(r=$corner_radius){
offset(r=$corner_radius, $fa=360/$shape_facets){
square_shape([size.x - $corner_radius*2, size.y - $corner_radius*2], delta, progress);
}
}
// for skin
function skin_rounded_square(size, delta, progress) =
rounded_rectangle_profile(size - (delta * progress), fn=36, r=$corner_radius);
function skin_rounded_square(size, delta, progress, thickness_difference) =
rounded_rectangle_profile(size - (delta * progress), fn=$shape_facets, r=$corner_radius);
SMALLEST_POSSIBLE = 1/128;
// I use functions when I need to compute special variables off of other special variables
@ -1151,6 +1200,42 @@ function vertical_inclination_due_to_top_tilt() = sin($top_tilt) * (top_total_ke
// of the keycap a flat plane. 1 = front, -1 = back
// I derived this through a bunch of trig reductions I don't really understand.
function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_inclination_due_to_top_tilt()) / ($total_depth);
function sign_x(i,n) =
i < n/4 || i > n*3/4 ? 1 :
i > n/4 && i < n*3/4 ? -1 :
0;
function sign_y(i,n) =
i > 0 && i < n/2 ? 1 :
i > n/2 ? -1 :
0;
function rectangle_profile(size=[1,1],fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
sign_x(index, fn) * [size[0]/2,0]
+ sign_y(index, fn) * [0,size[1]/2]
];
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];
function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];
// we do this weird key_shape_type check here because rounded_square uses
// square_shape, and we want flat sides to work for that too.
@ -1180,6 +1265,20 @@ module flat_sided_square_shape(size, delta, progress) {
[(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2]
]);
}
function skin_square_shape(size, delta, progress, thickness_difference) =
let(
width = size[0],
height = size[1],
width_difference = delta[0] * progress,
height_difference = delta[1] * progress,
square_size = [
width - width_difference - thickness_difference,
height - height_difference - thickness_difference
]
) rectangle_profile(square_size, fn=36);
module oblong_shape(size, delta, progress) {
// .05 is because of offset. if we set offset to be half the height of the shape, and then subtract height from the shape, the height of the shape will be zero (because the shape would be [width - height, height - height]). that doesn't play well with openSCAD (understandably), so we add this tiny fudge factor to make sure the shape we offset has a positive width
height = size[1] - delta[1] * progress - .05;
@ -1217,9 +1316,11 @@ module key_shape(size, delta, progress = 0) {
function skin_key_shape(size, delta, progress = 0, thickness_difference) =
$key_shape_type == "rounded_square" ?
skin_rounded_square(size, delta, progress) :
skin_rounded_square(size, delta, progress, thickness_difference) :
$key_shape_type == "sculpted_square" ?
skin_sculpted_square_shape(size, delta, progress) :
skin_sculpted_square_shape(size, delta, progress, thickness_difference) :
$key_shape_type == "square" ?
skin_square_shape(size, delta, progress, thickness_difference) :
$key_shape_type == "iso_enter" ?
skin_iso_enter_shape(size, delta, progress, thickness_difference) :
echo("Warning: unsupported $key_shape_type for skin shape. disable skin_extrude_shape or pick a new shape");
@ -3420,7 +3521,7 @@ module rounded_shape() {
// half minkowski in the z direction
color($primary_color) shape_hull($minkowski_radius * 2, $minkowski_radius/2, $inverted_dish ? 2 : 0);
/* cube($minkowski_radius); */
sphere(r=$minkowski_radius, $fn=48);
sphere(r=$minkowski_radius, $fn=$minkowski_facets);
}
}
/* %envelope(); */
@ -3795,7 +3896,7 @@ $outset_legends = false;
// Height in units of key. should remain 1 for most uses
$key_height = 1.0;
// Keytop thickness, aka how many millimeters between the inside and outside of the top surface of the key
$keytop_thickness = 1;
$keytop_thickness = 2;
// 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;
// Radius of corners of keycap
@ -3844,7 +3945,7 @@ $extra_long_stem_support = false;
// Key shape type, determines the shape of the key. default is 'rounded square'
$key_shape_type = "rounded_square";
// ISO enter needs to be linear extruded NOT from the center. this tells the program how far up 'not from the center' is
// ISO enter needs to be linear extruded NOT from the center when not using skin. this tells the program how far up 'not from the center' is
$linear_extrude_height_adjustment = 0;
// How many slices will be made, to approximate curves on corners. Leave at 1 if you are not curving corners
// If you're doing fancy bowed keycap sides, this controls how many slices you take
@ -3941,6 +4042,19 @@ $secondary_color = [.4412, .7, .3784];
$tertiary_color = [1, .6941, .2];
$quaternary_color = [.4078, .3569, .749];
$warning_color = [1,0,0, 0.15];
// 3d surface variables
// see functions.scad for the surface function
$3d_surface_size = 10;
$3d_surface_step = 1;
// normally the bottom of the keytop looks like the top - curved, at least
// underneath the support structure. This ensures there's a minimum thickness for the
// underside of the keycap, but it's a fair bit of geometry
$flat_keytop_bottom = true;
// how many facets circles will have when used in these features
$minkowski_facets = 30;
$shape_facets =30;
key();
}

View File

@ -37,7 +37,7 @@ module rounded_shape() {
// half minkowski in the z direction
color($primary_color) shape_hull($minkowski_radius * 2, $minkowski_radius/2, $inverted_dish ? 2 : 0);
/* cube($minkowski_radius); */
sphere(r=$minkowski_radius, $fn=48);
sphere(r=$minkowski_radius, $fn=$minkowski_facets);
}
}
/* %envelope(); */

View File

@ -1,17 +1,35 @@
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, fn) * [size[0]/2-r,0]
+ sign_y(index, fn) * [0,size[1]/2-r]
];
function sign_x(i,n) =
i < n/4 || i > n-n/4 ? 1 :
i > n/4 && i < n-n/4 ? -1 :
i < n/4 || i > n*3/4 ? 1 :
i > n/4 && i < n*3/4 ? -1 :
0;
function sign_y(i,n) =
i > 0 && i < n/2 ? 1 :
i > n/2 ? -1 :
0;
function rectangle_profile(size=[1,1],fn=32) = [
for (index = [0:fn-1])
let(a = index/fn*360)
sign_x(index, fn) * [size[0]/2,0]
+ sign_y(index, fn) * [0,size[1]/2]
];
function rounded_rectangle_profile(size=[1,1],r=1,fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];
function double_rounded_rectangle_profile(size=[1,1], r=1, fn=32) = [
let(max_fn = max(fn,8))
for (index = [0:max_fn-1])
let(a = index/max_fn*360)
r * [cos(a), sin(a)]
+ sign_x(index, max_fn) * [size[0]/2-r,0]
+ sign_y(index, max_fn) * [0,size[1]/2-r]
];

View File

@ -86,7 +86,7 @@ $extra_long_stem_support = false;
// Key shape type, determines the shape of the key. default is 'rounded square'
$key_shape_type = "rounded_square";
// ISO enter needs to be linear extruded NOT from the center. this tells the program how far up 'not from the center' is
// ISO enter needs to be linear extruded NOT from the center when not using skin. this tells the program how far up 'not from the center' is
$linear_extrude_height_adjustment = 0;
// How many slices will be made, to approximate curves on corners. Leave at 1 if you are not curving corners
// If you're doing fancy bowed keycap sides, this controls how many slices you take
@ -183,3 +183,7 @@ $secondary_color = [.4412, .7, .3784];
$tertiary_color = [1, .6941, .2];
$quaternary_color = [.4078, .3569, .749];
$warning_color = [1,0,0, 0.15];
// how many facets circles will have when used in these features
$minkowski_facets = 30;
$shape_facets =30;

View File

@ -32,9 +32,11 @@ module key_shape(size, delta, progress = 0) {
function skin_key_shape(size, delta, progress = 0, thickness_difference) =
$key_shape_type == "rounded_square" ?
skin_rounded_square(size, delta, progress) :
skin_rounded_square(size, delta, progress, thickness_difference) :
$key_shape_type == "sculpted_square" ?
skin_sculpted_square_shape(size, delta, progress) :
skin_sculpted_square_shape(size, delta, progress, thickness_difference) :
$key_shape_type == "square" ?
skin_square_shape(size, delta, progress, thickness_difference) :
$key_shape_type == "iso_enter" ?
skin_iso_enter_shape(size, delta, progress, thickness_difference) :
echo("Warning: unsupported $key_shape_type for skin shape. disable skin_extrude_shape or pick a new shape");

View File

@ -1,12 +1,12 @@
include <../libraries/rounded_rectangle_profile.scad>
module rounded_square_shape(size, delta, progress, center = true) {
offset(r=$corner_radius){
offset(r=$corner_radius, $fa=360/$shape_facets){
square_shape([size.x - $corner_radius*2, size.y - $corner_radius*2], delta, progress);
}
}
// for skin
function skin_rounded_square(size, delta, progress) =
rounded_rectangle_profile(size - (delta * progress), fn=36, r=$corner_radius);
function skin_rounded_square(size, delta, progress, thickness_difference) =
rounded_rectangle_profile(size - (delta * progress), fn=$shape_facets, r=$corner_radius);

View File

@ -37,7 +37,7 @@ module sculpted_square_shape(size, delta, progress) {
height - extra_height_this_slice
];
offset(r = extra_corner_radius_this_slice) {
offset(r = extra_corner_radius_this_slice, $fa=360/$shape_facets) {
offset(r = -extra_corner_radius_this_slice) {
side_rounded_square(square_size, r = $more_side_sculpting_factor * progress);
}
@ -46,7 +46,7 @@ module sculpted_square_shape(size, delta, progress) {
// fudging the hell out of this, I don't remember what the negative-offset-positive-offset was doing in the module above
// also no 'bowed' square shape for now
function skin_sculpted_square_shape(size, delta, progress) =
function skin_sculpted_square_shape(size, delta, progress, thickness_difference) =
let(
width = size[0],
height = size[1],
@ -64,10 +64,10 @@ function skin_sculpted_square_shape(size, delta, progress) =
extra_corner_radius_this_slice = ($corner_radius + extra_corner_size),
square_size = [
width - extra_width_this_slice,
height - extra_height_this_slice
width - extra_width_this_slice - thickness_difference,
height - extra_height_this_slice - thickness_difference
]
) rounded_rectangle_profile(square_size - [extra_corner_radius_this_slice, extra_corner_radius_this_slice]/4, fn=36, r=extra_corner_radius_this_slice/1.5 + $more_side_sculpting_factor * progress);
) double_rounded_rectangle_profile(square_size - [extra_corner_radius_this_slice, extra_corner_radius_this_slice]/4, fn=$shape_facets, r=extra_corner_radius_this_slice/1.5 + $more_side_sculpting_factor * progress);
/* offset(r = extra_corner_radius_this_slice) {
offset(r = -extra_corner_radius_this_slice) {
@ -85,10 +85,10 @@ module side_rounded_square(size, r) {
sw = iw / resolution;
union() {
if (sr > 0) {
translate([-iw/2, 0]) scale([sr, sh]) circle(d = resolution);
translate([iw/2, 0]) scale([sr, sh]) circle(d = resolution);
translate([0, -ih/2]) scale([sw, sr]) circle(d = resolution);
translate([0, ih/2]) scale([sw, sr]) circle(d = resolution);
translate([-iw/2, 0]) scale([sr, sh]) circle(d = resolution, $fa=360/$shape_facets);
translate([iw/2, 0]) scale([sr, sh]) circle(d = resolution, $fa=360/$shape_facets);
translate([0, -ih/2]) scale([sw, sr]) circle(d = resolution, $fa=360/$shape_facets);
translate([0, ih/2]) scale([sw, sr]) circle(d = resolution, $fa=360/$shape_facets);
}
square([iw, ih], center=true);
}

View File

@ -1,4 +1,6 @@
use <../functions.scad>
include <../libraries/rounded_rectangle_profile.scad>
// we do this weird key_shape_type check here because rounded_square uses
// square_shape, and we want flat sides to work for that too.
@ -28,3 +30,17 @@ module flat_sided_square_shape(size, delta, progress) {
[(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2]
]);
}
function skin_square_shape(size, delta, progress, thickness_difference) =
let(
width = size[0],
height = size[1],
width_difference = delta[0] * progress,
height_difference = delta[1] * progress,
square_size = [
width - width_difference - thickness_difference,
height - height_difference - thickness_difference
]
) rectangle_profile(square_size, fn=36);