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:
Bob - Home - Windows 2018-01-30 12:01:38 -05:00
parent f081e8b4cd
commit a537407cca
5 changed files with 96 additions and 53 deletions

View file

@ -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(){