mirror of
https://github.com/rsheldiii/KeyV2.git
synced 2024-11-26 14:54:21 +00:00
make shapes much more powerful by passing them a progress prop and starting width / height with width / height end delta
This commit is contained in:
parent
f081e8b4cd
commit
a537407cca
11
keys.scad
11
keys.scad
@ -20,4 +20,13 @@ module translate_u(x=0, y=0, z=0){
|
||||
translate([x * unit, y*unit, z*unit]) children();
|
||||
}
|
||||
|
||||
sa_row(2) u(2) cherry() key();
|
||||
dcs_row(2) u(2) dishless() cherry() {
|
||||
/* $inverted_dish = true; */
|
||||
$key_shape_type = "obloid";
|
||||
key();
|
||||
}
|
||||
|
||||
translate_u(3) u(2) dcs_row(3) dishless() cherry() {
|
||||
$key_shape_type = "obloid";
|
||||
key();
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ for (row = [0:len(60_percent)-1]){
|
||||
columnDist = sum([for (x = [0 : column]) 60_percent[row][x]]);
|
||||
a = 60_percent[row][column];
|
||||
translate_u(columnDist - (a/2), -row) dishless() dcs_row((row+4) % 5 + 1) u(a) cherry() {
|
||||
$width_difference = 0;
|
||||
$height_difference = 0;
|
||||
$key_shape_type = "obloid";
|
||||
if (a != 6.25) {
|
||||
key();
|
||||
} else {
|
||||
|
36
src/key.scad
36
src/key.scad
@ -28,19 +28,13 @@ $minkowski_radius = .33;
|
||||
// derived values. 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);
|
||||
function total_key_height() = $bottom_key_height + unit * ($key_height - 1);
|
||||
function total_key_width(delta = 0) = $bottom_key_width + unit * ($key_length - 1) - delta;
|
||||
function total_key_height(delta = 0) = $bottom_key_height + unit * ($key_height - 1) - delta;
|
||||
|
||||
// actual mm key width and height at the top
|
||||
function top_total_key_width() = $bottom_key_width + (unit * ($key_length - 1)) - $width_difference;
|
||||
function top_total_key_height() = $bottom_key_height + (unit * ($key_height - 1)) - $height_difference;
|
||||
|
||||
// side sculpting functions
|
||||
// bows the sides out on stuff like SA and DSA keycaps
|
||||
function side_sculpting(progress) = (1 - progress) * 2.5;
|
||||
// makes the rounded corners of the keycap grow larger as they move upwards
|
||||
function corner_sculpting(progress) = pow(progress, 2);
|
||||
|
||||
|
||||
// key shape including dish. used as the ouside and inside shape in key()
|
||||
module shape(thickness_difference, depth_difference){
|
||||
@ -84,7 +78,7 @@ module shape_hull(thickness_difference, depth_difference, extra_slices = 0){
|
||||
}
|
||||
}
|
||||
|
||||
//corollary is shape_hull
|
||||
//corollary is hull_shape_hull
|
||||
// extra_slices unused, only to match argument signatures
|
||||
module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_slices = 0){
|
||||
|
||||
@ -95,7 +89,7 @@ module linear_extrude_shape_hull(thickness_difference, depth_difference, extra_s
|
||||
translate([0,$linear_extrude_height_adjustment,0]){
|
||||
linear_extrude(height = height, scale = [width_scale, height_scale]) {
|
||||
translate([0,-$linear_extrude_height_adjustment,0]){
|
||||
key_shape(total_key_width(), total_key_height(), thickness_difference, thickness_difference, $corner_radius);
|
||||
key_shape(total_key_width(thickness_difference), total_key_height(thickness_difference));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,14 +106,6 @@ module hull_shape_hull(thickness_difference, depth_difference, extra_slices = 0)
|
||||
}
|
||||
|
||||
module shape_slice(progress, thickness_difference, depth_difference) {
|
||||
// makes the sides bow
|
||||
extra_side_size = $enable_side_sculpting ? side_sculpting(progress) : 0;
|
||||
// makes the rounded corners of the keycap grow larger as they move upwards
|
||||
extra_corner_size = $enable_side_sculpting ? corner_sculpting(progress) : 0;
|
||||
|
||||
// computed values for this slice
|
||||
extra_width_this_slice = ($width_difference - extra_side_size) * progress;
|
||||
extra_height_this_slice = ($height_difference - extra_side_size) * progress;
|
||||
skew_this_slice = $top_skew * progress;
|
||||
depth_this_slice = ($total_depth - depth_difference) * progress;
|
||||
tilt_this_slice = -$top_tilt / $key_height * progress;
|
||||
@ -128,11 +114,15 @@ module shape_slice(progress, thickness_difference, depth_difference) {
|
||||
rotate([tilt_this_slice,0,0]){
|
||||
linear_extrude(height = 0.001){
|
||||
key_shape(
|
||||
total_key_width(),
|
||||
total_key_height(),
|
||||
thickness_difference+extra_width_this_slice,
|
||||
thickness_difference+extra_height_this_slice,
|
||||
$corner_radius + extra_corner_size
|
||||
[
|
||||
total_key_width(thickness_difference),
|
||||
total_key_height(thickness_difference)
|
||||
],
|
||||
[
|
||||
$width_difference,
|
||||
$height_difference
|
||||
],
|
||||
progress
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,71 @@
|
||||
$fs=.1;
|
||||
unit = 19.05;
|
||||
|
||||
module key_shape(width, height, width_difference, height_difference, corner_size) {
|
||||
if ($key_shape_type == "iso_enter") {
|
||||
ISO_enter(width, height, width_difference, height_difference, corner_size);
|
||||
} else if ($key_shape_type == "normal") {
|
||||
roundedSquare([width - width_difference, height - height_difference], corner_size);
|
||||
} else if ($key_shape_type == "circle") {
|
||||
circle(d=width - width_difference);
|
||||
} else if ($key_shape_type == "square") {
|
||||
square([width - width_difference, height - height_difference], center = true);
|
||||
}
|
||||
}
|
||||
// side sculpting functions
|
||||
// bows the sides out on stuff like SA and DSA keycaps
|
||||
function side_sculpting(progress) = (1 - progress) * 2.5;
|
||||
// makes the rounded corners of the keycap grow larger as they move upwards
|
||||
function corner_sculpting(progress) = pow(progress, 2);
|
||||
|
||||
// centered
|
||||
module roundedRect(size, radius, center=true) {
|
||||
linear_extrude(height = size[2]){
|
||||
roundedSquare([size[0], size[1]], radius, center=center);
|
||||
module key_shape(size, delta, progress = 0) {
|
||||
if ($key_shape_type == "iso_enter") {
|
||||
ISO_enter(size, delta, progress);
|
||||
} else if ($key_shape_type == "normal") {
|
||||
roundedSquare(size, delta, progress);
|
||||
} else if ($key_shape_type == "circle") {
|
||||
circle(d=width);
|
||||
} else if ($key_shape_type == "square") {
|
||||
square(size - delta, center = true);
|
||||
} else if ($key_shape_type == "obloid") {
|
||||
obloid(size, delta, progress);
|
||||
}
|
||||
}
|
||||
|
||||
module roundedSquare(size, radius, center = true) {
|
||||
offset(r=radius){
|
||||
square([size[0] - radius * 2, size[1] - radius * 2], center=center);
|
||||
module obloid(size, delta, progress) {
|
||||
width = size[0];
|
||||
height = size[1] - delta[1] * progress; // TODO if we don't account for the delta somehow 1u keys will not render as the offset margin is greater than the size of the key. this does not work however
|
||||
|
||||
if (progress < .5 && false) {
|
||||
circle(d=5.5);
|
||||
} else {
|
||||
offset(r=height / 2.1) {
|
||||
square(size - [height / 1.05, height / 1.05] - delta * progress, center=true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module roundedSquare(size, delta, progress, center = true) {
|
||||
width = size[0];
|
||||
height = size[1];
|
||||
|
||||
width_difference = delta[0];
|
||||
height_difference = delta[1];
|
||||
// makes the sides bow
|
||||
extra_side_size = $enable_side_sculpting ? side_sculpting(progress) : 0;
|
||||
// makes the rounded corners of the keycap grow larger as they move upwards
|
||||
extra_corner_size = $enable_side_sculpting ? corner_sculpting(progress) : 0;
|
||||
|
||||
// computed values for this slice
|
||||
extra_width_this_slice = (width_difference - extra_side_size) * progress;
|
||||
extra_height_this_slice = (height_difference - extra_side_size) * progress;
|
||||
extra_corner_radius_this_slice = ($corner_radius + extra_corner_size);
|
||||
|
||||
offset(r=extra_corner_radius_this_slice){
|
||||
square(
|
||||
[
|
||||
width - extra_width_this_slice - extra_corner_radius_this_slice * 2,
|
||||
height - extra_height_this_slice - extra_corner_radius_this_slice * 2
|
||||
],
|
||||
center=center
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// corollary is roundedSquare
|
||||
// NOT 3D
|
||||
module ISO_enter(width, height, width_difference, height_difference, corner_size){
|
||||
module ISO_enter(size, delta, progress){
|
||||
width = size[0];
|
||||
height = size[1];
|
||||
function unit_length(length) = unit * (length - 1) + 18.16;
|
||||
|
||||
|
||||
@ -41,15 +78,13 @@ module ISO_enter(width, height, width_difference, height_difference, corner_size
|
||||
width_ratio = unit_length(1.25) / unit_length(1.5);
|
||||
height_ratio = unit_length(1) / unit_length(2);
|
||||
|
||||
// height and width difference currently don't do anything - but I think I should keep them. they don't do anything because we currently use scaling in the linear_extrude to express the difference in height and width of the top of the keycap
|
||||
|
||||
pointArray = [
|
||||
[ -width_difference/2, -height_difference/2], // top right
|
||||
[ -width_difference/2, -height + height_difference/2], // bottom right
|
||||
[-width * width_ratio + width_difference/2, -height + height_difference/2], // bottom left
|
||||
[-width * width_ratio + width_difference/2,-height * height_ratio + height_difference/2], // inner middle point
|
||||
[ -width + width_difference/2,-height * height_ratio + height_difference/2], // outer middle point
|
||||
[ -width + width_difference/2, -height_difference/2] // top left
|
||||
[ 0, 0], // top right
|
||||
[ 0, -height], // bottom right
|
||||
[-width * width_ratio, -height], // bottom left
|
||||
[-width * width_ratio,-height * height_ratio], // inner middle point
|
||||
[ -width,-height * height_ratio], // outer middle point
|
||||
[ -width, 0] // top left
|
||||
];
|
||||
|
||||
minkowski(){
|
||||
|
@ -38,10 +38,16 @@ module cherry_stem(depth, has_brim, slop, stem_inset, support_type) {
|
||||
difference(){
|
||||
union() {
|
||||
linear_extrude(height = depth) {
|
||||
roundedSquare(stem, 1, center=true);
|
||||
offset(r=1){
|
||||
square(stem - [2,2], center=true);
|
||||
}
|
||||
}
|
||||
if(has_brim) {
|
||||
roundedRect([stem_width*2, stem_height*2,brim_height], 1, 1, center=true);
|
||||
linear_extrude(height = brim_height){
|
||||
offset(r=1){
|
||||
square(stem - [2,2], center=true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
linear_extrude(height = cross_depth) {
|
||||
|
Loading…
Reference in New Issue
Block a user